Skip Navigation

[Resolved] No output when trying to display content conditionally based on Check box.

This thread is resolved. Here is a description of the problem and solution.

Problem:

Conditional display on custom checkboxes field values.

Solution:

You can try the Types shortcode with attributes "option" + "state", like this:

https://toolset.com/forums/topic/no-output-when-trying-to-display-content-conditionally-based-on-check-box/#post-2245701

Relevant Documentation:

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

This support ticket is created 3 years 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)

This topic contains 4 replies, has 2 voices.

Last updated by MargeP6083 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2244701

I want to display data based on user preference indicated by a checkbox. (Email, phone, etc)

Original custom field: hidden link

I tried this:
[wpv-conditional if="( $(wpcf-contact-preference) eq 'Email' )"][types field='company-email'][/types][/wpv-conditional]
I tried a conditional block with the same.

If I use NOT or 'ne', the display works. So is there something wrong with my syntax of the conditional?

hidden link

#2244971
email-value.png

Hello,

I have tried it in my localhost with a fresh WP installation + the latest version of Toolset plugins, the codes you mentioned above works fine.

Please make sure the "Email" option value is: Email

See my screenshot email-value.JPG

#2245207

Thank you, That is how it looks: hidden link

I see the issue. There are 3 choices. The user can select all 3 preferences if they want to be contacted in all three ways. But only the first value will shows when all 3 are selected.

If all 3 are selected, only Phone shows. If Phone is not selected and Email and Internal Messaging are ticked, only 2nd choice will show conditionally. How can I make all three conditionals appear when all 3 are selected?

[wpv-conditional if="( $(wpcf-contact-preference) eq 'Phone' )"]Phone: [types field='company-phone'][/types][/wpv-conditional]

[wpv-conditional if="( $(wpcf-contact-preference) eq 'Email' )"][types field='company-email' output='raw'][/types][/wpv-conditional]

[wpv-conditional if="( $(wpcf-contact-preference) eq 'Internal Messaging' )"]xxxxxxxxxx[/wpv-conditional]

#2245701

Thanks for the details, you can try the Types shortcode with attributes "option" + "state", like this:

[types field="contact-preference" option="0" state="checked"]Email: ...[/types]
[types field="contact-preference" option="1" state="checked"]Phone: ...[/types]
[types field="contact-preference" option="2" state="checked"]Internal Messaging: ...[/types]

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

#2246131

Works great! Documentation is really helpful.

My issue is resolved now. Thank you!