Problem: I would like to loop over the options for a checkboxes group field using Views, and display a different image per option.
Solution:
There is no built-in way to loop over checkbox options in a View, but you can use the syntax from the article below to write out some conditionals manually.
[wpv-conditional if="( '[types field='room-size' option='0'][/types]' eq 'filename1.jpg' )"] <img src="/wp-content/uploads/2019/04/filename1.jpg" /> [/wpv-conditional] [wpv-conditional if="( '[types field='room-size' option='1'][/types]' eq 'filename2.jpg' )"] <img src="/wp-content/uploads/2019/04/filename2.jpg" /> [/wpv-conditional] [wpv-conditional if="( '[types field='room-size' option='2'][/types]' eq 'filename3.jpg' )"] <img src="/wp-content/uploads/2019/04/filename2.jpg" /> [/wpvconditional]
You will replace room-size with the field slug from wp-admin, and replace the img srcs with full URLs. The 'filename1.jpg' in quotation marks at the end of the line should be replaced with whatever you have in the value of each checkbox.
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
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 2 replies, has 2 voices.
Last updated by 5 years, 9 months ago.
Assisted by: Christian Cox.