Skip Navigation

[Resolved] using contains in conditional block to check value of check boxes

This support ticket is created 3 years, 10 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.

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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by justinW-8 3 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2114535
Screen Shot 2021-07-14 at 11.58.25 AM.png
Screen Shot 2021-07-14 at 11.57.52 AM.png

this is the backend template for one of my post types. I have a check box that has an array of values, I want to be able to have conditions on each value so 55+ community, assisted living and so on but right now it only works with the first value as seen in the photos

#2114979

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot and suggest the best way to achieve this, I'll need to see exactly how this 'checkboxes' type custom field and the conditional block is set up.

Can you please share temporary admin login details, in reply to this message?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#2116167

Thank you for sharing the admin access.

Controlling the output based on the checkboxes type field is a bit tricky and you'll need to add a condition for each checkbox individually and then combine them together.

To get the value of only the first checkbox item "55+ Community", you can use the "types" shortcode, with the "option" attribute:
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes )


[types field=housing-offered option=0][/types]

Using this shortcode in the condition you can check whether a particular checkbox is checked or not:


( '[types field=housing-offered option=0][/types]' eq '55+ Community' )

Using the same approach, you can combine the conditions for multiple checkboxes, using the "AND" or "OR" operator:
https://toolset.com/documentation/legacy-features/views-plugin/nesting-and-combining-conditions/

For example, suppose, you want to check if the first 3 checkboxes "55+ Community", "Independent Living", and "Assisted Living", are all checked. The condition, in this case, would look like this:


( ( '[types field=housing-offered option=0][/types]' eq '55+ Community' ) AND ( '[types field=housing-offered option=1][/types]' eq 'Independent Living' ) AND ( '[types field=housing-offered option=2][/types]' eq 'Assisted Living' ) ) 

Likewise, if you'd like a condition where any one of these 3 checkboxes is checked, you'll just replace "AND" operators with "OR".

I hope this helps and please let me know if you need any further assistance around this.

#2116745

My issue is resolved now. Thank you!