Toolset allows you to easily display related posts on the front-end. You can display one related parent item, many related child items, or the information from the intermediary post type.
There are two ways to display related posts:
- In one-to-many relationships, display fields that belong to the “one” side.
- Display a list of the “many” related posts in both one-to-many and many-to-many relationships.
When we say “one”, we mean items that are connected as “one-to-many” and are on the “one” side.
For example, a venue can have many events, but each event belongs to only one venue. When displaying a single event, you can display information about its venue.
- Edit the Content Template for displaying the “many” side of the relationship (i.e. the template for “events”).
- You can use any Toolset block to display parent information.
- In the block properties, select the parent from Post Source.
- Select the field you would like to display.
You just added the venue’s details to the Content Template for events!
In Toolset, every time you need to display a list of items, you should use a View. This includes displaying “many” related items. You should use this in two cases:
- When displaying a list of items (the “many” side) in a one-to-many relationship
- When displaying related items in a many-to-many relationship
In our example, events have many speakers, so we’ll use a View to display them.
- Create or edit a Content Template used to display events.
- Insert a View block and create a new View.
- Select to display the post type you need (i.e. speakers) and then select the option to display posts related to the current post.
- Use blocks to design the output for your View. Because the View is already set to display related posts you don’t need to select the relationship in blocks you use to display dynamic content.
When you are designing a View for related content, in a many-to-many relationship, you may also want to display fields that belong to the relationship.
To do this, add Toolset blocks to the View and use the Post Source to select the relationship (only available if you’ve added custom fields to the relationship in question). Then, choose the field to display.
Display a single field
- Using Post Reference Field to Set-Up One-to-Many Relationships
- Selecting Parent Posts when Using Forms to Create Child Items
- How to set up Post Relationships in WordPress
- Front-End Forms for Connecting Related Posts
- What Are Post Relationships and How They Work
- Show all related topics...
- Many-to-Many Post Relationships in WordPress