Skip Navigation

[Resolved] Create post relation on form submit

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

Problem:
The customer asked how to create a post-relationship when a form to create a new post is submitted.

Solution:
Guided that this will require a custom function, attached to the "cred_save_data" hook, and will use the "toolset_connect_posts" function to connect the two posts.

Relevant Documentation:
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 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.

This topic contains 3 replies, has 2 voices.

Last updated by ferryv-3 2 months ago.

Assigned support staff: Waqar.

Author
Posts
#2426739

Dear support team,

Tell us what you are trying to do?

I want to automatic create a post relation between 2 posttypes when the second posttype post is created on the page of the first already existing post.

Is there any documentation that you are following?

no. (yes but i coudn't find much, see below ) Also not even sure where to put the code. functions.php is my best guess atm. figured i need the toolset_connect_posts hook but i cant really find how and where in the documentation.

Also because the new post will only get an id after saving it, the hook should probably trigger after the saving.
---------------------
The documentation:

// Connect a custom Author post with the ID of "5" to a custom Book post with the ID of "7" in a post relationship between Books and Authors
toolset_connect_posts( 'book-author', 5, 7 );
----------------------

Is there a similar example that we can see?

My users need to be able to make a offer to an item on the first posttype. This should link them together with a relationship so i can show the highest bids and follow up with the user.

Thanks in advance,

Ferry

#2426967

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ferry,

Thank you for contacting us and I'd be happy to assist.

Your understanding is correct and to connect the newly created post with the post where the new post form is used, you'll need a custom function.

The function will be attached to the "cred_save_data" hook ( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data ), and will use the "toolset_connect_posts" function ( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts ) to connect the two posts.

You'll find a relevant example code snippet in this reply:
https://toolset.com/forums/topic/linking-post-form-and-relationship-form/#post-2260119

regards,
Waqar

#2427203

Hi Waqar,

Thanks!! Working like a charm!

Ferry

#2427205

My issue is resolved now. Thank you!