[Resolved] Create child with cred form, assigning it to correct parent given by view-item
This thread is resolved. Here is a description of the problem and solution.
Problem:
Create child with cred form, assigning it to correct parent given by view-item
Solution:
You can use the Form's API hook "cred_save_data" in order to perform any customization after you save the post and to connect the post, you can use the post-relationship API function: toolset_connect_posts
This support ticket is created 4 years, 9 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
What I am trying to do:
I want the user to add a new "Custom Cluster Post" (child) for any "Custom Cluster" (parent) with a Cred form and have the new child automatically assigned the relationship with its correct parent, which is determined by the corresponding item of the parent-view.
I am aware of this solution: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/ (hiding the pre-selected option with css).
But since I am not on a single parent-page, but displaying all the parents within a view on the same page, this does not work. There is no option for the parent pre-selected (see screenshot).
I searched through the forum, but couldn't find a solution for this situation, pulling the correct parent from the view-item.
Any help would be very appreciated. Thanks!
Regards, Andreas
Hello. Thank you for contacting the Toolset support.
Can you please send me a problem URL where you are listing all the clusters and its associated child posts.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I see within your view you added the following shortcode:
[fusion_modal_text_link name="create-new-custom-cluster-post" class="" id=""]Add new post[/fusion_modal_text_link]
I'm not sure how you link the Toolset form to open with this shortcode. Can you please tell me how you link the Toolset form to open with the above shortcode?
Hi Minesh,
thank you for your reply.
This is a Avada shortcode, opening the form in a modal window. I removed this and put the Toolset form-shortcode "[cred_form form="create-custom-cluster-post"] " now directly into the view's template.
Now, to connect the child post with the parent:
- we need to use the Toolset Form's API hook: cred_save_data
- post relationship API function: toolset_connect_posts() to connect the post.
To do that, I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link
add_action('cred_save_data','func_connect_parent_to_child',15,3);
function func_connect_parent_to_child($post_id,$form_data) {
if ($form_data['id']==441) {
toolset_connect_posts('custom-cluster-custom-cluster-post',$_POST['related_parent_post_id'], $post_id);
}
}
I can see when you add the child post title with the following link: hidden link
The newly created child post will be connected automatically to the correct parent from where you created the child post.
I hope the solution I shared helps you to resolve your issue.