Skip Navigation

[Resolved] Repetable field

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by domenicoS 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1136959

Hi,

I have a custom post type accommodation. I've created a form to create a new one.

I've also a repetable group "room" lilend to the accommodation post type. I've created a CRED form to add new ones.
Whne when auto-generating a select the parent post filed is included.

But when I choose the accommodation related I see all the accommodation but I want to see only the accommodation which I'm the author not the accommodation are not the mine (bacuse this can get some problem).

How can I do?

#1137433

Hi,

In your case, it needs custom codes. I can get your website credentials in previous ticket:
https://toolset.com/forums/topic/display-a-multiple-instance-text-field-as-radio-field-in-the-post-form/#post-1130477

And have setup a demo in your website, here are detail steps:
1) Create a post view, get all "Current user accommodation posts"
hidden link
filter by:
Select posts with the author the same as the current logged in user.
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

In the view's loop output data as JSON format:

...
		<wpv-loop>
        [wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}
        [wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}
		</wpv-loop>
...

Enable option "Disable the wrapping DIV around the View"

2) Edit the post form "New Room"
hidden link

Setup a generic select field to replace default parent selector:

[cred_generic_field type='select' field='parent-accommodation-post']
{
"required":0,
"default":["111"],
"persist": 1,
"options":[[wpv-view name="current-user-accommodation-posts"]]
}
[/cred_generic_field]

Use view's shortcode(step 1) as the options
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

3) when user submit the form, we need to setup the relationship between "room" post and "accommodation" post, add custom codes in your theme file "functions.php":

add_action('cred_save_data', 'relate_accommodation_room_func',10,2);
function relate_accommodation_room_func($room_id, $form_data)
{
    // if a specific form
	$form_ids = array(26474);
    if (in_array($form_data['id'], $form_ids))
    {
        if (isset($_POST['parent-accommodation-post']) && !empty($_POST['parent-accommodation-post']))
        {
			$accommodation_id = $_POST['parent-accommodation-post'];
            // relate those two posts
            toolset_connect_posts('acc-room', $accommodation_id, $room_id);
        }
    }
}

The relationship slug "acc-room" is defined as repeatable field group slug, you can get it here:
hidden link
find the option "Group slug"

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Please test again, check if it is what you want.

#1137525
Screenshot -01.jpg

Hi Luo, thank you, it works perfectly.
But I've some code displayed (see the screenshot)
What is it?

#1137531

That is outputted from the post view of step 1), I have put it into post form "New Room" for debug the JSON codes:
hidden link

in section "Content", line 97, you can remove it now

#1137533

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.