Displaying Reverse Relationship
Explore how to display reverse relationships between WordPress post types by creating custom queries. Learn to fetch related teachers and upcoming events on course posts using meta queries and custom fields, ensuring dynamic and interactive theme functionality.
We'll cover the following...
The related_courses custom field displayed on the event and teacher posts links the course post type with the event and teacher post types. When creating an event or teacher post, we can choose the related courses. In the previous lesson, we saw how to display the relationship on the event and teacher posts.
In this lesson, we will focus on displaying the reverse relationship, i.e., displaying the events and teachers on a course post. This is not as straightforward as displaying the simple forward facing relationship.
The custom field which links the course and event post types is associated with the event post type. So how do we get the information of that custom field in the course post type? The answer lies in custom queries.
Custom query to get related teachers
The related_courses custom field can be accessed on a teacher post using the ...