In the examples that follow we will use a custom taxonomy called “Foreign language” defined with the Types plugin. This taxonomy is assigned to the Consultant custom post type:
Use the wpv-post-taxonomy shortcode to test if a post has at least one term assigned.
[wpv-conditional if="('[wpv-post-taxonomy type='foreign-language' format='slug' ]' ne '' )"] <strong>Foreign languages: </strong>[wpv-post-taxonomy type="foreign-language"] [/wpv-conditional]
The above code will output the following block (marked with the red border) if a consultant speaks at least one foreign language:
To check if a post has a specific term assigned we will use the WordPress core function called has_term. Before a WordPress core function can be used by Views, you must first register it:
- Open your Conditional Output GUI
- Switch to the Settings tab (on the left side)
- In the “Registered functions” section type in the has_term and press +Add button
- Close the window with the Close button
Now you can use the has_term in your condition to check if a post that is currently displayed has a specific term assign.
In our example, we want to emphasize the fact that a consultant speaks Chinese. We will display the relevant message only if a post has the ‘Chinese’ term assigned.
[wpv-conditional if="( has_term('Chinese', 'foreign-language', null) eq '1' )" ] <p class="special">This consultant speaks Chinese!</p> [/wpv-conditional]
- Chinese – the term name to be checked
- foreign-language – the slug of the taxonomy to be checked
If your View is listing all terms of a specific taxonomy (see the picture below), you can use wpv-taxonomy-slug or wpv-taxonomy-title shortcodes to test if a term currently displayed matches the desired value.
[wpv-conditional if="( '[wpv-taxonomy-slug]' eq 'chinese' )"] <strong>new!</strong> [/wpv-conditional]
The above code will output the following: