When we want to display related posts it is important to understand what content we are “currently displaying”. Depending on this, there are different ways of displaying items related to this content.

The following table makes this easier to understand.

What we want to achieveExample
When displaying a single post, display information about one related post.

Details

When displaying a single post, display multiple related posts.

Details

When displaying a single post, display multiple related posts and include information from the intermediary post type that connects two main post types.

Details

 

Workflows mentioned above allow you to display information about posts that are “one step away” from the current one. However, sometimes, you will need to display information from posts that are further away, for example, a child post of a child post. This is done a bit differently and you can find more information in the Examples section below.

When we say “one,” we mean items that are connected as “one-to-many” and are on the “one” side. An airport in the departures relationship is a good example of this. One airport has many flights departing from it.

When we display information about a specific flight, we want to display the name of the airport from which it departs.

Let’s go through the steps to do this.

  1. First, edit the Content Template that is used to display flights. Go to the Toolset → Content template page and click to edit the template.

Edit a Template of a Child Post
Edit a Template of a Child Post

  1. Add a Single field block.
  1. In the block properties select a field that comes from either the departure or arrival airport.

Single Field block properties
Selecting the post source in the Single Field block properties

In Toolset, every time you need to display a list of items, you must use a View. The same is true when you need to display “many” related items.

In our example, when displaying information about an airport, we want to display a list of all flights that depart from it.

Let’s go through the steps to do this.

  1. Create or edit a Content Template used to display the “one” side (in our example, the template for airports).
  2. Insert a View block and create a new View that displays flights.
  3. Use the Block navigation button to select the main View block and expand the Query Filter section in the right sidebar.
  4. Click the Add a filter button, select the Post relationship or repeatable field groups owner filter and then select the relationship by which you want to filter by.

Query Filter settings
Selecting the correct relationship in the Query Filter settings

  1. Use blocks to design the output for your View.

Designing How A View Outputs The Posts
Designing your custom list of posts using blocks

 

Displaying information from intermediary post types

Many-to-many relationships feature a so-called intermediary post type which connects two main types in a relationship. For example, Albums and Songs are connected by a post type called Album Tracks. These connecting post types can feature their own custom fields and you will sometimes need to display them.

In our example, when viewing an Album post, we want to list Songs that belong to it and display a Track Number for each song.

Let’s go through the steps to do this.

  1. Edit a Content Template for albums.
  2. Insert a View block and create a new View.
  3. Set the View to display the intermediary post type (in our example, Album Tracks).

Set the View to load the intermediary post type
Setting the View to load the intermediary post type

  1. Use the Block navigation button to select the main View block and expand the Query Filter section in the right sidebar.
  2. Click the Add a filter button, select the Post relationship or repeatable field groups owner filter and then select the relationship by which you want to filter by.

Adding a Post Relationship filter to the Query Filter
Adding a Post Relationship filter to the Query Filter settings

  1. Design your display for the items in the View using the View Loop. Remember, you are listing posts of the intermediary post type. For post fields that belong to the main related post types, in our example Songs and Albums, you need to set the appropriate post selection options.
A.) Add the Fields and Text block and then click the Add Field or View button.
B.) Click the Post selection tab and select following option: A post related to current post, set by a Types relationship. Now, select the relationship in question (Album Tracks) and which “side” of the relationship you want to display (Songs). Click the Insert shortcode button.

As mentioned, sometimes you need to display information from posts that are not directly related to the current post. The following two pages provide examples of how to achieve this:

  1. Displaying Related Child Posts
  2. Displaying Fields of Grandparents

Toolset also features a special custom field called Post Reference. It allows you to easily connect two posts and display their related post information.  You can read more about this on the page about using Post Reference Field To Display Data Of Related Posts.

When you have post types connected through a relationship you can set up conditional output based on the values coming from related posts. You can read more about this on the page about Conditional output based on post relationships.

 

Or, you can skip ahead to the page about building front-end forms for connecting posts.