Skip Navigation

[Resolved] Types checkboxes custom field when unchecked, save 0 in DB, showing as checked

This support ticket is created 6 years, 2 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
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 4 replies, has 2 voices.

Last updated by Ana 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1153897

Ana

I have a site using Toolset and I have several custom fields of type checkboxes, with the option "When unchecked, save 0 to the database" set.
I also use content templates to view the posts in the front end, displaying these fields.
In the content template I'm insetting the Types custom fields and for these checkboxes on the display options I'm using "Custom values for selected and not selected states" resulting in something like the following:

[types field='<name-of-field>' state="checked"]<span class="a35-symbol-checkbox-checked"></span>[/types][types field='<name-of-field>' state="unchecked"]<span class="a35-symbol-checkbox"></span>[/types]

I would expect that the custom values depending on the checkbox value be displayed. This is not happening/working with the last Types version 3.1.2.

Any advice on this would be appreciated. Thanks

#1153990

Hi, first I would like to point out that saving 0 to the database is known to cause problems with custom searches. If possible, it's best to avoid using this setting. It's advised to update your content as explained here: https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/

If it's not possible to update your content, we have a patch available for the checked / unchecked display issue here:
https://toolset.com/errata/checkbox-and-checkboxes-fields-saving-0-will-display-checked-custom-value-even-if-not-checked/

You may need to recreate your types field shortcodes using the Fields and Views button, because they don't seem to include the option numbers for each possible checkbox. The correct format looks like this:

[types field='name-of-field' state="checked" option="0"]checked[/types]
[types field='name-of-field' state="unchecked" option="0"]unchecked[/types]<br />
[types field='name-of-field' state="checked" option="1"]checked[/types]
[types field='name-of-field' state="unchecked" option="1"]unchecked[/types]<br />
[types field='name-of-field' state="checked" option="2"]checked[/types]
[types field='name-of-field' state="unchecked" option="2"]unchecked[/types]<br />
#1155348

Ana

Hi, thanks for the solution.

First, I'd like to apologize because I referred a custom field of type "checkboxes" and presented a shortcode example of a custom field of type "checkbox" (single).
Actually I have both types of custom fields, and the problem is comum.

The solution of updating the custom fields settings and then the content would be a problem.
I already have dozens of customs fields in dozens of forms with hundreds of posts in the client production site.

So, the solution presented by the errata is welcome.
It worked perfectly.

Thanks again.

#1155543

Okay great, thanks for the update.

#1156400

Ana

My issue is resolved now. Thank you!