Skip Navigation

[Resolved] How to use conditional output with a checkboxes field

This support ticket is created 8 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 3 replies, has 2 voices.

Last updated by Luo Yang 7 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#390164

Hi there

I have a checkboxes custom field titled Business Type. The checkboxes include Accommodation Provider, Retailer and Service Provider.

I am trying to: use conditional output in my content template to only show accommodation content when the Accommodation Provider checkbox is ticked.

I have tried the following but nothing appears in any category:

[wpv-conditional if="('[types field=‘business-type’ separator=''][/types]' eq ‘Accommodation Provider’)"]accomm content[/wpv-conditional]

[wpv-conditional if="('[types field=‘wpcf-business-type’ separator=''][/types]' eq ‘Accommodation Provider’)"]accomm content[/wpv-conditional]

[wpv-conditional if="( $(wpcf-business-type) eq 'Accommodation Provider' )"]accomm content[/wpv-conditional]

I've read through a lot of documentation but can't figure out where I'm going wrong, any help would be appreciated.

Thanks

#390420

Dear John,

Since the Types custom checkboxes field stores value in a serized array, it is not possible to use wpv-conditional shortcode to do what you want. I suggest you use Types shortcode, like this:

[types field="business-type" option="0" state="checked"]Accomm Content is checked[/types]
[types field="business-type" option="1" state="checked"]Retailer is checked[/types]
[types field="business-type" option="0" state="checked"]Service Provider is checked[/types]

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

#390649

Many thanks, that works great.

Another question - can the same be done with a custom hierarchical taxonomy? if so, what would the shortcode look like?

Thanks.

#390809

To compare with terms of custom taxonomy, please try with [wpv-conditional] shortcode using wordpress function has_term(), for example:

[wpv-conditional if="( has_term('your-term-slug', 'post_tag', null) eq '1' )"]
This post has a Tag named Sedo
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
section "Data origin"
http://codex.wordpress.org/Function_Reference/has_term

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