Skip Navigation

[Gelöst] No output when trying to display content conditionally based on Check box.

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 2 Jahre, 4 Monate. 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.

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
- 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 Antworten, has 2 Stimmen.

Last updated by MargeP6083 vor 2 Jahre, 4 Monate.

Assisted by: Luo Yang.

Author
Artikel
#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!

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