Skip Navigation

[Resolved] Conditional based on View shortcode attribute

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View that uses a shortcode attribute. Inside that View, I would like to use a conditional that tests the value of that shortcode attribute.

Solution: Use the wpv-attribute shortcode inside a View to access the value of any shortcode attribute applied to that View.

[wpv-conditional if="('[wpv-attribute name="servicetype"]' eq 'bible-talk')"]
This is the bible talk servicetype View
[/wpv-conditional]
[wpv-conditional if="('[wpv-attribute name="servicetype"]' eq 'bible-study')"]
This is the bible study servicetype View
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-309292

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikeH-3 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1578607

I have this in a view template I made: [wpv-conditional if="( '[wpv-view]' eq 'bible-talk' )"] Show this bible talk [/wpv-conditional]

However even though the current view on the website is bible-talk, it still doesn't show this text above. Am I using the wrong syntax?

#1578751

Hi, are you trying to display the slug of a specific View? Write the slug in the View manually, and it will only be displayed in that View. There's no need for a conditional, just add the text. Similarly if you want to display the slug of a Content Template, just write that slug in the Content Template. It will be displayed in that Content Template, there's no need for a conditional. Maybe I don't understand what you're trying to accomplish?

#1578757

No, because I'm using this same view for multiple pages but different servicetypes. For example this:

[wpv-view name="sermons" servicetype="bible-talk"]
or
[wpv-view name="sermons" servicetype="bible-study"]

But depending on which servicetype they choose to show, I need a field showing based on that.

#1578843

You can use the wpv-attribute shortcode to access the value of any arbitrary View shortcode from inside that View:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-309292

[wpv-conditional if="('[wpv-attribute name="servicetype"]' eq 'bible-talk')"]
This is the bible talk servicetype View
[/wpv-conditional]
[wpv-conditional if="('[wpv-attribute name="servicetype"]' eq 'bible-study')"]
This is the bible study servicetype View
[/wpv-conditional]
#1579119

My issue is resolved now. Thank you!