Skip Navigation

[Resolved] Re-Order Checkbox Field and Use it for Conditionals

This support ticket is created 3 years, 4 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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1855687

Tell us what you are trying to do?
Change the order of a checkbox field without having to completely rebuild my template conditionals.

Looking for a better way, because this can't be right.

Is there any documentation that you are following?
https://toolset.com/forums/topic/conditional-display-depending-on-checkbox-2/

I have 39 options on a checkbox field because that's how many options the field requires at this time.

I just added a few more options and changed the order. This seems to have made the "option" numbers in my template invalid. So now I need to completely redo every conditional in my template. One of many examples below...

[wpv-conditional if="( '[types field="dealer-service-offerings" option="34"][/types]' eq 'Turbo/Superchargers' ) OR ( '[types field="dealer-service-offerings" option="35"][/types]' eq 'Performance Exhaust' ) OR ( '[types field="dealer-service-offerings" option="36"][/types]' eq 'Engine Modifications' )"]
                                , performance mods
[/wpv-conditional]

Surely there is a completely static method of identifying the options so we don't have to rewrite the content template everytime we need to add or arrange options?

#1856015

Hello,

There isn't such kind of feature with custom checkboxes field, see our document:
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.

In your case, you might consider to use a custom taxonomy instead of custom checkboxes field, so you will be able to use WP function has_term() in [wpv-conditional] shortcode, and check if current post has specific term, for example:
https://toolset.com/forums/topic/conditional-display-woo-category/
And you will be able to mange terms of the taxonomy easily.

More help:
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/
https://developer.wordpress.org/reference/functions/has_term/

#1856965

That sounds like a good solution, but the problem with checkboxes only arises when the order of the options is changed, and that order does need to change as new options are added. With taxonomies (please correct me if I'm wrong) you can't change the order the options. So... I'm thinking my only option is to do thirty-nine individual radio fields with YES / NO as the options.

Turbo/Superchargers - yes/no
Performance Exhaust - yes/no
Engine Modifications - yes/no
+36 more.

That's incredibly tedious, but it will allow me to control the order and replace the need for a static option value.

Is changing the option from a zero-based index number to something static post-reorder even possible? If so, I'll submit a feature request.

#1857407

Yes, you are right, ith taxonomies, you can't change the order the options manually.

In your case, you might consider custom codes, for example:
1) Use custom checkboxes field "dealer-service-offerings"
2) Create a custom PHP function, do these:
a) Get field "dealer-service-offerings" value:
https://toolset.com/documentation/customizing-sites-using-php/functions/
b) Check if field value contains the specific value:
hidden link
3) Then use above PHP function in wpv-conditional shortcode:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

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