Skip Navigation

[Resolved] Display Images from Checkbox Values

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

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 support ticket is created 5 years, 8 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.

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 christianS-11 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1219671

Hi,

I have a User Registration form with Checkboxes where can select images. (Label = img tag).
The values of each checkbox is the filename of the image (it needs to be translatable with wpml)

In the view I'd like to display the selected images but I am not sure how the get the separate values to build a img tag in the output.

Can you help me?

#1220076

Hi, there is no built-in way to loop over checkbox options in a View, but you can use the syntax from this article to write out some conditionals manually: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

[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" />
[/wpv-conditional]

...

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.

#1220172

Hi,
thanks so far. In the meantime I put the complete img tag as option value (which seems to work) but your solution looks cleaner 😉