Just getting started with the Template Editor? Check out the main documentation first!
Conditions can be used to show or hide specific parts of the template depending on the taxonomy terms a specific grid item has associated with it or when it has a custom field with a specific value.
Important note: conditions will always show their content in the Template Editor preview. They will only work as expected on your actual site.
Using taxonomy terms conditions
Categories and tags are examples of taxonomies that can be associated with a post and that can be used as conditions. For this example we want to display “Recommended read!” in a grid template when a specific post has the “featured” tag set.
Here’s how you’d add this condition in the template editor:
The type here can be either “term_slug” or “term_id” and the values parameter will have to be a list of slugs or IDs accordingly. To have the condition apply to more than 1 value you use a semicolon in between:
[wpupg-condition type="term_id" key="category" values="1;24;53"]...[/wpupg-condition]
If you add multiple values you can specify wether you want the condition to show when
any value matches or only if all values match:
[wpupg-condition type="term_slug" key="category" values="blue;red" match="any"]Will show when the item has category blue or category red[/wpupg-condition]
[wpupg-condition type="term_slug" key="category" values="blue;red" match="all"]Will only show when the item has both category blue and category red[/wpupg-condition]
Finally the inverse attribute can optionally be added:
[wpupg-condition type="term_id" key="my_custom_taxonomy" values="353" inverse="1"]Will only show if this item does NOT have term 353 of my_custom_taxonomy associated with it[/wpupg-condition]
Using custom field conditions
Any custom field associated with posts can be used as a condition in the Template Editor. In this example we want to show “Top rated recipe!” if the item has a custom field “wprm_rating_average” with value “5”:
Values can optionally be a list of values, separated by a semicolon:
[wpupg-condition type="field" key="wprm_rating_average" values="4;5"]Top rated recipe![/wpupg-condition]
The inverse attribute can optionally be added:
[wpupg-condition type="field" key="wprm_rating_average" values="5" inverse="1"]This will show if the custom field is not equal to "5"[/wpupg-condition