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