Problem:
I have a Checkboxes Field and want to output content conditionally depending on that Field's checked options, using HTML conditionals.
What's the syntax?
Solution:
Checkboxes are complex fields, that either store an empty array in the database if not checked and set to save nothing or an array with the value chosen.
Note that save 0 for unchecked is set, then it'll instead of saving empty array save a 0 when not checked.
We do not recommend to use "When unchecked, save "0" to the database.".
In Toolset HTML Conditionals this, however, should not be of concern.
Your HTML Condition to output "XY" when no option is checked and the options themselves if checked would look like this:
[wpv-conditional if="( $(wpcf-your_field_slug) eq '0' )"]test[/wpv-conditional]
Above will only show if no option is checked at all (Note, this example uses the *Save 0 for unchecked*. Otherwise, you'd compare against "empty" such as
[wpv-conditional if="( $(wpcf-your_field_slug) eq '')"]test[/wpv-conditional]
).
Relevant Documentation:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
This topic contains 3 Antworten, has 2 Stimmen.
Last updated by Engedi vor 4 Jahre, 9 Monate.
Assisted by: Beda.