Skip Navigation

[Resolved] Displaying related posts in many-to-many relationship

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 10 months, 4 weeks ago.

Assisted by: Waqar.

Author
Posts
#2676619
CleanShot 2023-12-29 at 10.33.29@2x.png
CleanShot 2023-12-29 at 10.29.52.jpeg

I have a custom post type Books and a custom post type Talent (for Authors and/or Illustrators). I have a many-to-many relationship between them. On the template for Books, I want to display other Books that share the same Talent association. Every attempt I've made returns no results.

hidden link is under construction but I could provide a link

#2676765

Hi,

Thank you for contacting us and I'd be happy to assist.

The current view's query filter settings would work if you wanted to show the related books on a single talent post page.

But for showing other books related to current book's related talent posts, you'll need two views and not one:

1. The first parent view will be set to show or cycle through all the related talent posts of the current book.

2. The second child view will be set to show the related books with respect to the talent post found in the loop of the parent view.

You can follow these steps:

a). Create a new content template 'CT to show the related Books', without assigning it to any post type.

b). Inside this template you'll create a view that will be set to show the books related to the talent post coming from the parent view's loop.

c). In the template for the single books, you'll create a view that shows the talent posts related to the book where this view is shown.

d). In the loop of this view for the related talents, you'll load the content template 'CT to show the related Books', so that it repeats for each found talent post.

I hope this helps and let me know if you need further assistance.

regards,
Waqar