Skip Navigation

[Resolved] Many-to-many related content in Single Field or Text and Field content type

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

Problem: I would like to display information from a related post in a many-to-many relationship, using a "Fields and Text" or a "Single Field" block. In the past I was able to do this with a one-to-many relationship to display information from the parent post in the child post template, but it doesn't work for a many-to-many relationship.

Solution: Since there is the possibility of having multiple related posts instead of just one, you should use a View of related posts to display this information. Add a post relationship query filter, and insert the field in the View's loop.

Relevant Documentation: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

This support ticket is created 4 years, 8 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
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 4 replies, has 2 voices.

Last updated by Vane 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1526915

Hi,

I had a one-to-many Relationship which worked properly, I was able to insert into CPT "Brand Post"s content template the related CPT "Brand"s CF named Brand Name, by selecting Text and Field content type and having the option of Custom Field / Post Source = from Relationship...

I decided to change the Relationship to many-to-many, and now I don't see this option there.
Pls. note though I'm able to add multiple Brands to one Brand Post on backend, but I can not add it to the Brand Post Content template, so it only displays the first related Brand Name.

Pls. note I DON'T have intermediary CPT between Brands and Brand Posts

Thank you

#1527529

Right, since there is now a possibility of multiple related posts, you can't just use one shortcode to display all of them. You'll need to create a View of related posts, and include the post title in the View's loop. This will loop over all the related posts and produce a list of post titles, one for each related post. Your View should include a post relationship filter. We have some documentation for displaying multiple related posts available here: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

Let me know if you have questions about that.

#1531859

Thank you!

#1532329

Hi,

what you suggested by referring to the linked docs has worked, but only partially.

Speaking about eg.:
mydomain.com/brand-post/a-story-about-aqua-and-burger-king

1) We can not define a separator between the listed items (elsewhere in Toolset we can),
so this time it looks rather misleading like:
AQUA Burger King,
but it should look like eg.:
AQUA, Burger King
or
AQUA | Burger King

2) In CRED forms it still doesn't work properly, I got a:
"There is a problem with @brand-brand-post.parent field. Please check CRED form."
error.
The related form item is:

[cred_field field='@brand-brand-post.parent' value='[wpv-search-term param="parent"]' class='form-control' output='bootstrap' select_text='--- Must select ---']

Thank you

#1533443

The Loop Style had to be set to List with separators, as described here:
https://toolset.com/documentation/user-guides/views/view-layouts-101/

Thank you!