Skip Navigation

[Resolved] Let user set post-relations in post form

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

Problem:

I want to allow users to select parent posts in a many-to-many (M2M) relationship directly within a post form.

Solution:

In Toolset, managing many-to-many (M2M) relationships typically requires a separate Relationship Form. This is because post forms are designed to edit the main content, taxonomies, and custom fields of a post, while relationship management is handled separately.

Steps to Use a Relationship Form for M2M:

- Create a Relationship Form to manage the connections between posts.

- Display the form on the front end where users can connect or disconnect related posts.

Relevant Documentation:

https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

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 1 voice.

Last updated by a.R 1 week, 3 days ago.

Assisted by: Christopher Amirian.

Author
Posts
#2786995

a.R

Hi there 🙂

How can users select parent posts (many to many) in a post form?

Thank you 🙂

#2787225

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. In the typical workflow, an edit post Form does not allow you to manage many-to-many (M2M) relationships, it only edits the main content, taxonomies, and custom fields of the post itself. Normally M2M relationships are managed in a separate Relationship Form, which does not allow editing the main post contents, taxonomies or custom fields. Those processes are usually kept separate. In a one-to-many relationship, an edit post form for the child post type will allow you to choose a parent post, but in a M2M relationship the situation is more complex and requires a separate Form as explained in our lessons here:
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

So the preferred solution here is a separate Relationship Form to manage M2M relationships. If you want to implement a more custom solution that allows you to manage M2M relationships directly in an edit post Form, we have several PHP APIs available for inspecting and managing post relationships with Forms submissions:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

Please consider that we can not provide custom code as it is outside of our support scope. You are welcome to ask for help from a contractor:

https://toolset.com/contractors/

Thanks.

#2787308

a.R

Ok, thank you, Christopher.

And could you just tell me how you consider an approach to display both forms side by side, to make it look like one form, and to trigger one submission by the other?

Regards, Achim

#2787317

Christopher Amirian
Supporter

Languages: English (English )

Hi Achim,

That is not possible with conventional Toolset features.

One idea can be to get the results of first form submission in cred_save hook, and feed it via some sort of JavaScript, localization to the second form and forced to submit it via JavaScript.

That is way complicated, and as I mentioned in the previous reply needs a professional developer to do so.

Thank you very much.

#2787543

a.R

Ok, thank you, Christopher