Using Views shortcodes

You can use some of the Views shortcodes in the if-expression of the wpv-conditional shortcode. This allows you to use conditional logic on the output you get from those shortcodes.

The list of all Views shortcodes that can be used in conditional statements is available in the Conditional output dialog when you select Views Shortcodes in the Field dropdown.

Checking the type of the post displayed

Checking the type of the post displayed
[wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]This is  a post[/wpv-conditional]

Checking If A Post Excerpt Exists

You can test the output generated by a View shortcode for a non-empty value

Checking If A Post Excerpt Exists
[wpv-conditional if="( '[wpv-post-excerpt]' ne '' )"] 

<h3>More about the consultant</h3> 

[wpv-post-excerpt] [/wpv-conditional]

Checking For The Current User Data

Use the wpv-current-user shortcode to find the current user and display text based on who they are.

Views - Conditional Output - Current User Data
Views – Conditional Output – Current User Data

Checking For The Current User Data
[wpv-conditional if="( '[wpv-current-user]' eq 'bruce' )"]Bruce is logged in now [/wpv-conditional]

If you need to check if the user is logged in and then display something based on that condition, you can use the following code.

Checking User Information
[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'true' )"] 
  I am logged in
[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'false' )"]
I am logged out

Checking taxonomy shortcodes

Visit the page about displaying taxonomies conditionally to see how you can use wpv-post-taxonomy and wpv-taxonomy-slug shortcodes in your conditions.

Checking Types plugin shortcodes

Shortcodes from Types plugin, that are used to display custom fields or user meta fields can also be used in the conditional statements.

Checking Types plugin shortcodes
[wpv-conditional if=" '[types field="consultant-price-per-hour"][/types]' gt '0' "]
Price per hour: [types field="consultant-price-per-hour"][/types] [/wpv-conditional]

[wpv-conditional if="( '[types usermeta="user-signature"][/types]' ne '' )"]
How do you do [types usermeta="user-signature"][/types] [/wpv-conditional]


Checking Custom shortcodes

You can use custom shortcodes in your conditions. For this, the manage_options capability is required, meaning that only admins can do this.

Before using a custom shortcode inside a conditional, you need to register it. To do so, visit the Toolset -> Settings page and click the Front-end Content tab. There, simply add your shortcode to the Third-party shortcode arguments section.

Checking Custom shortcodes
[wpv-conditional if="( '[extra_features]' ne '' )"]Extra features: [extra_features][/wpv-conditional]

Other examples

  1. Conditional HTML Output in Views
  2. Views Pagination – Split Content into Pages
  3. Creating WordPress Custom Post Archives
  4. Filtering Views Query by Post ID
  5. Passing Arguments to Views
  6. How to Create Custom Searches and Relationships for Users
  7. Using Post Reference Field To Display Data Of Related Posts
  8. How to create a WordPress thumbnail slider in minutes
  9. How to filter by related posts
  10. Displaying Taxonomy Term Fields on the Front-end
  11. Filtering Views Query by Custom Fields
  12. Filtering Views Query by Taxonomy
  13. Filtering Posts by User-Selected Taxonomy
  14. Filtering Views Query by Post Status
  15. Checking fields and other elements for Empty/Non-empty Values
  16. Building Custom Searches for Any Content Type
  17. Views – the Loop Output
  18. Displaying Related Child Posts
  19. Filtering Views Query by Post Parent
  20. Filtering Views Query by Author
  21. Filtering Views Query by Date
  22. Filtering Views for a specific text string – search
  23. Filtering Views Query by Sticky Posts
  24. Date Filters
  25. Using a Content Template in a View loop
  26. Displaying Fields of Grandparents
  27. Displaying taxonomies conditionally
  28. WooCommerce Views – Calculated fields and batch update
  29. Views Output Formats – Bootstrap, Table, Grid, Ordered and Un-Ordered Lists
  30. Display index numbers for posts listed with Views
  31. Adding custom JavaScript to Views
  32. Using shortcodes in conditions
  33. Allowing visitors to sort the front-end results
  34. Advanced Settings for Custom Search
  35. Selecting Parent Posts when Using Forms to Create Child Items
  36. How to Use Views Custom Search on Large Sites
  37. Views Inside Views – Display Nested Multidimensional Lists
  38. Infinite Scrolling for WordPress Content
  39. Conditional output based on post relationships
  40. Creating sliders with Views
  41. Nesting and combining conditions
  42. Debugging Conditional Output
  43. Shortcodes within Shortcodes – Control Any Shortcode with Types Fields
  44. Displaying Brother Pages