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 GUI when you select “Views Shortcodes” in the Data origin 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

Views - Conditional Output Excerpt

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 he is.

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]
[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'false' )"]
I am logged out
[/wpv-conditional]

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 be also 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