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
[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
[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.
[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.
[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 also be used in the conditional statements.
[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.
[wpv-conditional if="( '[extra_features]' ne '' )"]Extra features: [extra_features][/wpv-conditional]
Other examples
-
Conditional HTML Output in Views
-
Create Image Galleries Using Repeating Custom Fields
-
Displaying Taxonomy Term Fields on the Front-end
-
Creating WordPress Custom Post Archives
-
Passing Arguments to Views
-
How to Create Custom Searches and Relationships for Users
-
How to filter by related posts
-
How to create a WordPress thumbnail slider in minutes
-
Using Post Reference Field To Display Data Of Related Posts
-
Filtering Views Query by Post ID
-
Views Pagination – Split Content into Pages
-
Filtering Views Query by Custom Fields
-
Filtering Views Query by Taxonomy
-
Filtering Posts by User-Selected Taxonomy
-
Filtering Views Query by Post Status
-
Filtering Views Query by Author
-
Displaying Related Child Posts
-
Views – the Loop Output
-
Checking fields and other elements for Empty/Non-empty Values
-
Filtering Views Query by Post Parent
-
Building Custom Searches for Any Content Type
-
Filtering Views Query by Date
-
Filtering Views for a specific text string – search
-
Filtering Views Query by Sticky Posts
-
Date Filters
-
Displaying Fields of Grandparents
-
Displaying taxonomies conditionally
-
Using a Content Template in a View loop
-
WooCommerce Views – Calculated fields and batch update
-
Views Output Formats – Bootstrap, Table, Grid, Ordered and Un-Ordered Lists
-
Display index numbers for posts listed with Views
-
Using shortcodes in conditions
-
Advanced Settings for Custom Search
-
Allowing visitors to sort the front-end results
-
Adding custom JavaScript to Views
-
Selecting Parent Posts when Using Forms to Create Child Items
-
How to Use Views Custom Search on Large Sites
-
Views Inside Views – Display Nested Multidimensional Lists
-
Infinite Scrolling for WordPress Content
-
Conditional output based on post relationships
-
Nesting and combining conditions
-
Creating sliders with Views
-
Debugging Conditional Output
-
Shortcodes within Shortcodes – Control Any Shortcode with Types Fields
-
Displaying Brother Pages