Skip Navigation

[Resolved] Creating a condition on a checkbox group

This support ticket is created 4 years, 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 4 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1363925

Hi,

I imported a lot of data from a database to WP using WP All Import and the toolset plugin...

There were two fields that were on a similar topic (whether we can publish after two years or never or we can always publish if none are checked)... Since in the original database these were two fields with either 0 or 1 for checked or unchecked, what I did is I created a checkbox group with two checkboxes in it... Each checkbox has the store value of either 0 or 1 depending on whether it is checked or not.

I think it did import well, but what I didn't know is that now it stores that into ONE field (the checkbox group name) in the database... So, now I need to make conditions on this field to know whether one or the other of the checkboxes are checked... but the problem is that it is stored in the database in that format: a:2:{s:64:"wpcf-fields-checkboxes-option-67f25a958f84788f52ca7a3929bf2ad4-1";a:1:{i:0;s:3:"0|1";}s:64:"wpcf-fields-checkboxes-option-e4da57fcbdcb186d1f0c394df1e423b1-1";i:0;}

How can I create a condition (in Views) to check whether the first one or the second one is checked? I saw that it stores it like that "0|0"... so I tried a SQL syntax like this "%0|1%" but it doesn't work... I also tried with the above syntax changing the 0 to 1 when needed, but it doesn't work either...

Thank you

#1363975

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Actually - checkboxes fields are stored in special format that is called serialized array.

To display conditional content based on the checkbox option of checkboxes there are two ways either you can go with [wpv-conditional] shortcode Or use the types shortcode.

For example:

[wpv-conditional if="( '[types field="checkbox-field-slug" option="0"][/types]'  eq '1' )"]
     Option 0 is checked.
[/wpv-conditional]
[wpv-conditional if="( '[types field="checkbox-field-slug"" option="1"][/types]' eq '1' )"]
        Option 1 is checked.
[/wpv-conditional]

OR

Even you can try following way:

 [types field="checkbox-field-slug" option="0" state="checked"]
     Option 0 is checked
[/types]
 
[types field="checkbox-field-slug" option="1" state="checked"]
       Option 1 is checked
[/types]

[types field="checkbox-field-slug" option="0" state="unchecked"]
       Option 0 is NOT checked
[/types]

More info:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.