Problem: I have a View that displays different results based on a shortcode attribute. I would like to use the output of this View in a conditional. If the results are not empty, I would like to show a text header.
Solution: Avoid using a View's results in a conditional. You'll run into lots of problems with extra spaces, markup, and nested attribute quotation marks, causing the conditional to fail. Instead, use the View's wpv-items-found block to your advantage and display the text here. You can pass arbitrary text into a custom shortcode attribute, and display it in the View using the wpv-attribute shortcode.
View shortcodes:
[wpv-view name="degree-listings" wpvposttag="academic programs, FST, major" heading="Majors"] [wpv-view name="degree-listings" wpvposttag="academic programs, FST, masters" heading="Masters"] [wpv-view name="degree-listings" wpvposttag="academic programs, FST, cas" heading="Certificates of Advanced Study"]
Loop output:
[wpv-layout-start] [wpv-items-found] <strong>[wpv-attribute name="heading"]</strong> <!-- wpv-loop-start --> <wpv-loop> your loop stuff goes here </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found]No items found[/wpv-no-items-found] [wpv-layout-end]
Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-309292
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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 2 replies, has 2 voices.
Last updated by Suzanne Wenger 4 years, 10 months ago.
Assisted by: Christian Cox.