Tell us what you are trying to do?
I created a checkbox list as custom field in a CPT, now i would like to check the value of the checkboxes and return links depending on the selection.
Is there any documentation that you are following?
no
Is there a similar example that we can see?
no
here is the code i use in my content Template:
[wpv-conditional if="( $(wpcf-psy-werbung) eq '1' )"]
Sunny Trips<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '2' )"]
Flixbus<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '3' )"]
Deutsche Bahn<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '4' )"]
Sunny Trips<hr>
[/wpv-conditional]
Even if i check all checkboxes it only returns the first one.
Hi,
Welcome to Toolset support.
You’re comparing a multi-checkbox field as if it were a single value. Toolset checkboxes store multiple selections, so $(wpcf-psy-werbung) won’t match the way you expect. The supported way is to test each option individually and check whether it’s selected.
Use the Types shortcode with the option attribute; it returns "1" if that specific option is checked:
option="0" is the first option in the field definition
option="1" is the second, and so on
So your conditionals should look like this (adjust option indexes to match your field’s option order):
[wpv-conditional if="( '[types field='psy-werbung' option='0'][/types]' eq '1' )"]
Sunny Trips<hr>
[/wpv-conditional]
[wpv-conditional if="( '[types field='psy-werbung' option='1'][/types]' eq '1' )"]
Flixbus<hr>
[/wpv-conditional]
[wpv-conditional if="( '[types field='psy-werbung' option='2'][/types]' eq '1' )"]
Deutsche Bahn<hr>
[/wpv-conditional]
[wpv-conditional if="( '[types field='psy-werbung' option='3'][/types]' eq '1' )"]
Sunny Trips<hr>
[/wpv-conditional]
For more information:
https://toolset.com/forums/topic/conditional-display-if-option-from-multi-checkbox-is-checked/
Thanks.