Skip Navigation

[Resolved] Displaying a parent post via a M2M relationship

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 an M2M relationship, but the shortcode only shows one post.

Solution: Use a View to loop over related posts when there is more than one possible result.

This support ticket is created 5 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.

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 Ben 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1210766

Ben

When a shortcode is used within Views to display a parent post, what is the default behaviour when more than 1 result is found? For example when it is a M2M relationship.

I am testing this and I am finding that only one parent post is shown, but how is this decided? And can It be changed?

#1210776

You won't be able to use shortcodes effectively this way to display related posts in an M2M relationship, since many posts could be related. The recommended approach is to create a View of the other post type, add a post relationship filter for your M2M relationship (set by the current post, or the current post in the loop, or a shortcode attribute, for example), then output the post information in the View as you loop over parent posts. Apply any additional filters necessary to show the parent(s) you want.

#1210873

Ben

Thank you Christian.

I will do it this way.

Out of interest, what is the logic behind which parent post it shown as I have detailed above?

#1210880

I don't have that information. If there is something specific you want to achieve, I can ask the developers.

#1211999

Ben

No need to Christian, it was purely out of interest.

Thank you for all your help with this.