Hi,
Do I have this right?
If I want the child parent selector to be pre-filled out then:
1. Create form for parent and child.
2. on submit from parent form redirect MUST go to parent just created (can't go to child form if I want parent selector pre-filled with just created parent)
3. On page of newly created parent I put link to child form - then parent selector will be pre-filled.
Since my parent has 3 different post type children this is not a great work flow. (back and forth, back and forth...)
Is the above correct?
Thanks,
Scott.
2. on submit from parent form redirect MUST go to parent just created (can't go to child form if I want parent selector pre-filled with just created parent)
You can use the cred_success_redirect API to skip this step and go directly to the child form with URL parameter applied. The new parent form must be configured to "redirect to another page" after form submission. Then add this custom code to your child theme's functions.php file:
add_filter('cred_success_redirect', 'custom_child_redirect',10,3);
function custom_child_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==12345)
return $url . "?some-param=" . $post_id;
return $url;
}
Change 12345 to match the new parent post Form ID, and change some-param to match the parent post select field attribute urlparam in the new child post Form.
More information about this API here: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
Thinking about it some more...not sure would work because my set-up is a multi-site with each user having their own subsite, so there's no static URL.
Thanks.
The $url variable isn't static in this example, it represents whatever you choose in the Form redirect settings. So on one subsite, everyone will be redirected to one URL with different URL parameters. On another subsite, everyone will be redirected to one other URL with different URL parameters. Am I understanding correctly? If the redirect URL is consistent per subsite, then this approach will be fine. For example:
Subsite 1 parent Form redirects to:
subsite1.mainsite.com/create-child-post?parent-id=12345
Subsite 2 parent Form redirects to:
subsite2.mainsite.com/create-child-post?parent-id=23456
Subsite 3 parent Form redirects to:
subsite3.mainsite.com/create-child-post?parent-id=34567
etc.
Thanks Christian,
I did it another way....as I don't understand but also I don't know what the subsite might be called, it's created on the fly by the user using wpUltimo. They choose their own name.
Regards.