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:
- Click the conditional output button.
- Select the field you want to check the conditional against.
- Another dropdown option appears. In it select a relationships you need.
- Select the comparison type and value.
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.
At the diailog box you need to do the following:
- 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.
- Choose != as a Comparison value.
- 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.