Hi 🙂
We would like to embed a content form in a post to create a child to that post.
What do we have to add here to get that CHILD automatically, so that users won´t have to explicitly tell it should be that child?
Thank you 🙂
<!-- wp:toolset/cred-form {"form":"{\u0022ID\u0022:\u00225737\u0022,\u0022post_title\u0022:\u0022Einen Gedanken hinzufügen\u0022,\u0022post_name\u0022:\u0022einen-gedanken-hinzufuegen\u0022,\u0022formType\u0022:\u0022post\u0022,\u0022formAction\u0022:\u0022new\u0022}","formType":"post","formAction":"new"} -->
<div class="wp-block-toolset-cred-form">[cred-form form="einen-gedanken-hinzufuegen" ]</div>
<!-- /wp:toolset/cred-form -->
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Do you meant that you want to link the post you are creating using the child post form to the parent post and the parent post is the current post where the form is added?
Yes, the Form is added inside the parent post.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
If you mean you want to connect the child post created using the form "einen-gedanken-hinzufuegen" automatically to the parent post where the form is added.
What if you try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset
For example:
add_action('cred_save_data', 'func_set_parent_as_current_post',10,2);
function func_set_parent_as_current_post($post_id, $form_data){
if ($form_data['id'] == 99999 ){
$parent_id = $form_data['container_id'];
$parent = toolset_connect_posts( 'replace-relationship-slug', $parent_id, $post_id );
}
}
Where '
- Replace 99999 with your original form ID
- Replace replace-relationship-slug with your original post relationship slug.
More info:
=> 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
This will NOT work with 'wpcf-breed', right?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Ahh.. That's not needed and I adjusted the code with previous reply and removed that line of the code as it's not required.
Here is the modified code:
add_action('cred_save_data', 'func_set_parent_as_current_post',10,2);
function func_set_parent_as_current_post($post_id, $form_data){
if ($form_data['id'] == 99999 ){
$parent_id = $form_data['container_id'];
$parent = toolset_connect_posts( 'replace-relationship-slug', $parent_id, $post_id );
}
}
Where
- Replace 99999 with your original form ID
- Replace replace-relationship-slug with your original post relationship slug.