Skip Navigation

[Resolved] Displaying a one-to-many post relationship on a view

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

Problem: I have a View of Courses and I would like to display all the related Faculty members for each Course. Courses and Faculty are related in a one-to-many relationship where Courses are one and Faculty are many.

Solution:
Use a nested View of Faculty posts, with a post relationship Query Filter set by the current post in the loop.

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

Last updated by Jackie 5 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1221489

Hi there,

I'm building a course catalog for a school of art and design. One page lists a set of courses. Each course is a custom post type called "course." Every course is connected to one or more "faculty" custom post types through a Types relationship (course-to-faculty, which is a one-to-many relationship). Here is an example of the type of page under discussion:

hidden link

Here's my question. The page above is generated using a View. The view is displaying the first faculty member related to the course post. The code in the "Template for this View" looks like this:

	<div class="col-sm-3"><p class="section_detail_subhead">Faculty</p></div>
	<div class="col-sm-3"><p>[wpv-post-title item="@section-to-faculty-relationship.child"]</p></div>

The question is, how do I display multiple faculty members here? Do I need to embed a view within a view? Is that even possible?

Thank you!

Saul

#1221750
Screen Shot 2019-03-27 at 10.29.32 AM.png

Hi, this is certainly possible with nested Views. In your case, you will create a 2nd View of Faculty members. In this View, set up a Post Relationship filter based on your Course - Faculty relationship, that displays related posts as set by the current post in the loop. See the screenshot for an example. Then in the loop editor, build your list of Faculty Members. Finally, insert this View just after the Faculty subheader in your View of Courses.

#1228290

Super nifty. This is exactly what I needed. Thank you, Christian!

-Saul