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 use this in Views, Content Templates, and WordPress Archives.

This allows you to create conditionals based on values that come from posts other than the currently displayed one.

To display content conditionally, based on values coming from related posts, use the following steps:

  1. Click the conditional output button.
  2. Select the field you want to check the conditional against.
  3. Another dropdown option appears. In it select a relationships you need.
  4. Select the comparison type and value.

Creating a conditional display based on related content
Creating a conditional display based on related content

Example

Let us have a look at one example. We could have a site where real estate agents sell houses. There is a relationship between these two post types. Some agents offer virtual tours of houses. They use Skype for such virtual tours.

You can create such conditional output that shows the potential buyers for which houses virtual tours are available. When an agent that offers virtual tour lists a new house a note about that will automatically be displayed on the page that displays tours.

First go ahead and create a View that lists Houses. Use the Loop wizard to add all the fields that you want to display. Also add the text that you want to be conditionally displayed. Select this text and click the conditional output button.

 

Insert conditional shortcode dialog box will open up.

Use of post relationships in conditions
Use of post relationships in conditions

At the diailog box you need to do the following:

  1. In the first dropdown of the Field section select Skype field and in second dropdown select the relationship. In our case this is an agent_house relationship.
  2. Choose != as a Comparison value.
  3. Leave Value field empty.

As you can see, our conditional checks will return only those agents that have any data in Skype field.

When you save the newly created View, all you need to do is insert it to a page. Now, the list of houses will display the text “Book your virtual tour!” next to all houses for which agents provide Skype tours.