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!
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
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
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
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'