Skip Navigation

[Resolved] embedded content form to add a child to current post

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 6 months ago.

Assisted by: Minesh.

Author
Posts
#2702762

a.R

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

#2702803

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?

#2702965

a.R

Yes, the Form is added inside the parent post.

#2703004

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

#2703012

a.R

This will NOT work with 'wpcf-breed', right?

#2703014

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.