Problem:
How to use the found count of a View in a conditional statement?
A View outputs just the found count—using the wpv-found-count shortcode—but it doesn't work when used in a conditional shortcode that tests the resulting number.
Solution:
The problem is that the View doesn't just output the number, it includes a wrapper div and some white space.
The wrapper div can be disabled with its setting, and the whole of the Loop Output can be compressed to eliminate whitespace, like so:
[wpv-layout-start][wpv-items-found][wpv-found-count]<!-- wpv-loop-start --><wpv-loop></wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found][/wpv-no-items-found][wpv-layout-end]
That will then output just the number with no extra whitespace or markup and so can be used in a conditional shortcode.
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 4 replies, has 2 voices.
Last updated by 5 years, 4 months ago.
Assisted by: Nigel.