Skip Navigation

[Resolved] Select posts for many to many relationship in post form

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

Problem: I have 2 post types in a many-to-many relationship. In a form that creates custom post type #1, I would like to be able to choose 3 items from CPT #2 to relate to the new post.

Solution: It's not currently possible to manage M-2-M relationships in a new post Form or an edit post Form. The best way to manage M2M relationships is to use Relationship Forms. You can also use generic fields and custom code with our PHP APIs.

Relevant Documentation:
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/front-end-forms/inserting-generic-fields-into-forms/

This support ticket is created 5 years, 1 month 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by nabils 5 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1403663

Tell us what you are trying to do?

Hi,
I created a many to many relationship between property and agent. I want to add a relationship filed in property form to be able to add from 0 to 3 agent for a specific property. However, I can not find the relationship field to add in the form.

#1404953

Hello, in the current software you must create a separate Relationship Form to manage many-to-many relationships between two existing posts. You can find those in wp-admin > Toolset > Relationship Forms. It is not possible to create posts and also define many-to-many relationships in the same Form...that would require custom code. We have documentation for Relationship Forms available here: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

If you're comfortable writing your own custom code, we offer some PHP APIs that you can use to accomplish something like this. For example, the Toolset Post Relationships API can be used to link two posts in a many-to-many relationship:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

You can also use the Post Relationships API to inspect relationships and find related posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

There is an API for Forms, so you can execute custom code when a Form is submitted:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Forms also includes generic fields, which you can use to capture other information:
https://toolset.com/documentation/user-guides/front-end-forms/inserting-generic-fields-into-forms/

#1405225

My issue is resolved now. Thank you!