Skip Navigation

[Resolved] linking parent and child forms

This support ticket is created 6 years, 4 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.

Our next available supporter will start replying to tickets in about 1.94 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 22 replies, has 3 voices.

Last updated by Nigel 6 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#607098

That is something to look forward to!

You did sum it up correctly.

#607526

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andre

OK, for that kind of workflow you need to

- change the settings of your form to publish the parent posts so that on submission it redirects to the page which holds your child post form
- to set the parent post when that page loads it will look for a URL parameter that looks something like this: ?parent_slug_id=99
- so you will need to use the cred_success_redirect hook (https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect) to append a URL parameter with the parent post id

/**
 * Set parent post ID when redirecting to child form
 */
function tssupp_set_parent_on_redirect( $url, $post_id, $form_data ){

	// Edit as required
	$form_id = 117;
	$parent_slug = 'zipy-card';

	$param = "";

	if ( $form_data['id'] == $form_id ) {
		$param = "?parent_" . $parent_slug . "_id=" . $post_id;
	}

	return $url . $param;
}
add_filter( 'cred_success_redirect', 'tssupp_set_parent_on_redirect', 10, 3 );

That demonstrates the technique required.

You will need to employ a similar technique to chain together the forms adding child posts but in that case the parent ID will no longer be available from the $post_id parameter (which will be the ID of the newly created child post). But that new child post will have the parent post ID stored as post meta (with a key of '_wpcf_belongs_parent-slug_id') so you can use get_post_meta to retrieve it and use that to construct the URL parameter in the same way.

https://developer.wordpress.org/reference/functions/get_post_meta/

Let me know how you get on.

#615188
zipy parent changes.png
zipy functions.php.jpg

Hi Nigel,

sorry for the long delay in reverting back to you. This is getting slightly the better of me. I have completed the first setting. (image attached)
I have added the function, (image included) ( the parent id is 105.)
I assume the second point was covered by the functions added.
This is where you lost me.

The balance of your comments are totally over my head, Sorry

#615626

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andre

I've read through the thread again to remind myself of what the issue is.

I suggest we worry about getting the first part working—going from creating the parent post to adding a child post—before worrying about adding multiple child posts.

In the parent post form you have set it to redirect to the page "View: Zipy Card child entries".

That concerns me slightly because it looks like you are redirecting to a page that contains a View to display child posts.

The target page is supposed to include the form to publish child posts.

Publish a page, add the cred form for child posts to it, then update your parent post form to point to that page.

Double-check that the ID of the parent post form is 105 (the edit you made to the code).

Now when you publish a parent post, it should redirect to the page with the child post form, where you can add a child post to the newly published parent. The parent field in the child post form should have the correct parent post pre-selected. You will probably want to hide that field with CSS so that your users do not change it, but first confirm that the correct parent is selected.

If that is working we can continue to the next part, adding more child posts.

#616732
zipy functions.php.jpg

Hi Nigel,

Ok, i have done exactly as you said. I have renamed the Child form page to same without the "View:" part. It does open the child form but it does not select the parent Id in the parent Id field. The parent name is listed in the drop-down but not selected.
I have double checked the Id for the parent form and it is 105. I am including a screen print of this code for to double check.
I have checked the URL to be "zipy-card-only" and not "zipy-card" i have checked both options but neither gives me the expected result.

Thx

#616800

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Nigel is on vacation today. He will get back to you as soon as possible once he get back to work on Monday.

#616952

Thx Minesh!

#617469

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andre

In the code sample you specify the parent slug as "zipy-card-only". Is that the correct slug of your zipcard custom post type?

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