Skip Navigation

[Resolved] Conditional output based on multiple checkboxes

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

Problem:

I have a field called "schutzart-ip" (type: multiple checkboxes). It has 2 values checked (IP66 & IP67). Showing the content of these fields works without problem.

But when I try to show a conditional text if these two values are checked, it only recognises, that IP66 is checked, and wont output the conditional text.

https://toolset.com/forums/topic/conditional-output-based-on-multiple-checkboxes/#post-1225569

Solution:

You can setup the shortcode like this:

https://toolset.com/forums/topic/conditional-output-based-on-multiple-checkboxes/#post-1225586

Relevant Documentation:

https://toolset.com/forums/topic/conditional-output-based-on-multiple-checkboxes/#post-1225586

This support ticket is created 5 years, 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by maximilianD 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1225569

I have a field called "schutzart-ip" (type: multiple checkboxes). It has 2 values checked (IP66 & IP67). Showing the content of these fields works without problem.

But when I try to show a conditional text if these two values are checked, it only recognises, that IP66 is checked, and wont output the conditional text.

This is my code:

{!{wpv-conditional if="( $(wpcf-schutzart-ip) eq 'ip66' ) AND ( $(wpcf-schutzart-ip) eq 'ip67' )" debug="true"}!}TEST[/wpv-conditional]

The debug looks like this:

####################
wpv-conditional attributes
####################
Array
(
[if] => ( $(wpcf-schutzart-ip) = 'ip66' ) AND ( $(wpcf-schutzart-ip) = 'ip67' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-schutzart-ip) = 'ip66' ) AND ( $(wpcf-schutzart-ip) = 'ip67' )
--------------------
--------------------
Converted expression: ( 'ip66' = 'ip66' ) AND ( 'ip66' = 'ip67' )
--------------------

#1225586

Hello,

I suggest you try to follow our document to setup wpv-conditional shortcode:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value

For example there are only two options in the custom checkboxes field "schutzart-ip":
- ip66 (option index is 0)
- ip67 (option index is 1)

You can setup the shortcode like this:

{!{wpv-conditional if="( '[types field='schutzart-ip' option='0'][/types]' eq 'ip66' ) AND ( '[types field='schutzart-ip' option='1'][/types]' eq 'ip67' )" debug="true"}!}
TEST
{!{/wpv-conditional}!}

Notice, you will need to change the attribute "option" according to your custom checkboxes field settings:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
option:
"zero-based index number"
e.g. option=”0″ Will output the value for the option number specified.

#1225592

My issue is resolved now. Thank you!