Skip Navigation

[Resolved] The automatic attachment to the post does not work

This thread is resolved. Here is a description of the problem and solution.

Problem:
The automatic attachment to the post does not work

Solution:
You can use Toolset Form hook cred_save_data with post relationship API function toolset_connect_posts dynamically.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/the-automatic-attachment-to-the-post-does-not-work/#post-1078741

Relevant Documentation:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 3 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.

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 7 replies, has 2 voices.

Last updated by Serhii 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1076159

Page (rent house) - hidden link

Add review form on this page - hidden link

Problem - hidden link

I want to add review for parrent post, but toolset say to me "select post".

i read this https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/ but dont understand how it work, i have the same settings - hidden link but it is doesnt work.

Please help, what i am doing wrang?

#1076191

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - do you want to display parent post field on the review form or you just want that it should be automatically attach the post to parent or remain by default selected?

Please share access details as well so I can see the review form. I have set the next reply to private which means only you and I have access to it.

#1078652

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry but could you please share problem URL where I can see your review form and what do you want exactly.

As I understand - review form is added to parent post already and when you write review, you want to connect to it's associated parent where the review form is displayed automatically?

#1078741

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following code to your current theme's functions.php file to dynamically connect the parent/child post using Toolset Form hook cred_save_data with post relationship API function toolset_connect_posts

add_action('cred_save_data','func_connect_child_posts',15,2);
function func_connect_child_posts($post_id,$form_data) {
    if ($form_data['id']==129) {
          
        toolset_connect_posts('dom-otzyvy',$_POST['@dom-otzyvy.parent'], $post_id);
    }
}

I've removed the parent field from your Toolset form and replaced it with Generic hidden filed which holds the parent post ID as default value where the review form is display currently, as given under:

[cred_generic_field field='@dom-otzyvy.parent' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

Now, please try to add a review: hidden link

And when you will check in backend - the post will be automatically connected. Could you please confirm it works at your end as well.

#1079471

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please confirm it works at your end as well.

#1080280

It doesn't work, i see this error - hidden link

But I care about another. Yours implementation is very difficult. I believed that this could be done without using php, hooks etc =(

I read this article https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected

There is no mention of use php/hooks (part "Creating forms when a parent post is preselected"). Perhaps there is an easier way?

=======

Is not it logical, when a user wants to leave a review for the object, so that review immediately became attached to this object?

#1081407

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I read this article https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected
==> Yes - this is true. This is also a possible way.

I shared the hook solution because I thought you want to use post relationship API hook to connect the post automatically (even I confirm this before but may be we do not understand eachother).

I will take care of your another issue with new ticket - please feel free to close this ticket:
=> https://toolset.com/forums/topic/split-the-automatic-attachment-to-the-post-does-not-work-maximum-allowed-amount-association/

#1083686

thanks, it's work