Hello,
We are building a news site, and we need to link multiple PEOPLE posts to multiple NEWS posts. So the form we want says "Who is this post related to?" and asks them to search for and select multiple PEOPLE (posts), then add the NEWS content and publish the NEWS post. Our contractor says that we can not do it the way we want, which is to add multiple PEOPLE via a repeater field. He says Toolset is only capable of doing it this way:
- first link A 'person' to A 'news'
- then B 'person' to A 'news' or B 'news'
- but can't select both A+B 'persons' to add to A 'news' or B 'news'
Is that correct? Is there a way (in a front-end form) to connect multiple PEOPLE posts to each NEWS post?
Thank you!
Hi, it sounds like your contractor's assessment is accurate. It sounds like you have a many-to-many post relationship between People and News. You would like to create a Form that publishes a News post and also connects that News post to multiple People posts. That is not currently possible in the current system for two reasons:
1. A Form that creates News posts cannot also establish M2M relationship links. Post creation and relationship management must be handled in separate Forms. Two Forms are required in the current system: a Post Form to create News posts and a Relationship Form to connect (only) 2 posts in a M2M relationship.
2. A single Relationship Form can only link 2 posts in an M2M relationship. There is currently no bulk-assignment of multiple relationship links in a single Relationship Form.
So there is no built-in way to achieve exactly what you want. You need custom programming that incorporates our Post Relationships and Forms APIs to create a viable workaround. I recently helped another User set up something similar in another ticket here: https://toolset.com/forums/topic/how-to-pre-select-more-than-one-parent-on-a-child-post-submission-form/
Your contractor may be able to use this as a reference to set up something like what you want to achieve.
Thank you for the help.
My contractor says the code in that link only allows the 'news' post to be set to one 'people' post. How can we set it to many, instead?
Can you pretty please fix this soon for a future update so it doesn't require code? I'm sure lots of people need this, and we definitely will for multiple projects we have in. 😉
My contractor says the code in that link only allows the 'news' post to be set to one 'people' post.
There must be a miscommunication somewhere because the other ticket clearly discusses associating multiple posts to the new post. That's kind of the whole point of the ticket. See in the resolution summary at the top of the ticket:
"2. Edit the child post Form using Expert Mode in the Form Builder. Click "Add generic fields" above the code editor and choose a multiselect generic field."
Multiselect means you can select multiple posts to relate to the new post created by the Form.
See also in the resolution summary this section of code:
foreach($ms_selections as $ms_selection) {
toolset_connect_posts( $relationship_1_slug, $ms_selection, $post_id); // while looping over selected parents, connect them to the new child post programmatically
}
This part of the code loops over the multiselect selections and programmatically connects each one to the new post in the M2M relationship. If your contractor has a technical question about implementation, feel free to ask it directly here. Is there something specific that is different between our scenarios preventing this approach in your case?
Can you pretty please fix this soon for a future update so it doesn't require code? I'm sure lots of people need this, and we definitely will for multiple projects we have in.
I can add your vote to this feature request in our work queue. It's a long-standing request, but I don't realistically suspect it will be added to the software within the next few months based on current schedules and priorities.