Skip Navigation

[Resolved] Parent created w/CRED. Pass parent ID to child _wpcf_belongs_parent_id value=''

This support ticket is created 8 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)

Tagged: 

This topic contains 5 replies, has 3 voices.

Last updated by coryA-2 8 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#351217

The CRED form on this page creates a parent post: hidden link. Please fill out the form and click submit.

On submission of the parent CRED form, you will be redirected to this page to create a child post: hidden link. On the child CRED form, there is a drop-down menu to "Select Parent."

I want to get the ID of the parent post that was just created by the CRED form on the last page and insert that ID into "value" of child's _wpcf_belongs_landing-page_id so the user does not have to "Select Parent" from the drop-down menu:

[cred_field field='_wpcf_belongs_landing-page_id' value='INSERT PARENT ID HERE']

How can I get the parent post ID of a parent that was freshly created from a CRED form and pass that ID to "value" of the child CRED form?

I don't code. So, please give very specific step-by-step instructions when answering my question so I can follow along.

Let me know if you need any clarification.

Thank you!

#351307

Dear ryan,

Yes, it is possible within CRED + Types,
1) when user submit a parent post successfully, you can redirect user to the CRED child form with CRED filter hook "cred_success_redirect":
https://toolset.com/documentation/user-guides/cred-api/#csr

2) in above custom function pass URL parameter "parent_landing-page_id" to target URL

For example, add below codes into your theme/functions.php:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==123){
		$url = get_permalink(430);
		$url .= '?parent_landing-page_id=' . $post_id;
	}
    return $url;
}

Please replace 123 with the CRED form ID for create the parent "landing-page", replace 430 with the page ID of create child post

#351518

Thank you! That worked perfectly. Now, here's the next part of my question:

Next, the CRED form of the first child post (hidden link) redirects to another CRED form that will create a second child post (hidden link). The second child should also be a child of "landing-page."

How can I assign the second child to the same parent "landing-page?"

Thank you!

Derik

#351560

Dear Derik,

Same as above, you can add below codes in your theme/functions.php:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==456){
        $parent_id = get_post_meta($post_id, '_wpcf_belongs_landing-page_id', true);
        $url = get_permalink(430);
        $url .= '?parent_landing-page_id=' . $parent_id;
    }
    return $url;
}

Please replace 456 with the CRED form ID for create first child post, replace 430 with the page ID of create second child post

#351749

Perfect! Luoy, you rock!

#366793

Louy how do you "pass URL parameter "parent_landing-page_id" to target URL". I have added this code to my functions like this

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==5705){
$url = get_permalink(5704);
$url .= '?parent_landing-page_id=' . $post_id;
}
return $url;
}

but my child page loads a 404 page with this url - 'hidden link'

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