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?
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/
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.
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/