Skip Navigation

[Resolved] Is there a way to do a conditional If associated terms is empty?

This support ticket is created 4 years, 2 months 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.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Project Weblife 4 years, 2 months ago.

Author
Posts
#1828047

I am creating a view in Toolset and I want to use a conditional that says..
if this post (from current loop item) has a selected term in this taxonomy, display this text.... else, don't display any text.

I can sort of do this by doing the following...
if this post (from current loop item) has term A or term B or term C or term D selected, then display this text.... else, don't display any text.

This means I have to update the view every time a term changes or a term gets added. I develop the theme so if I can add a custom function to do that, it would not be a problem.

Here's the example code from my loop item.

[wpv-conditional if="( CONTAINS(#(division),'General Obstetrics and Gynecology') ) OR ( CONTAINS(#(division),'Gynecologic Oncology and Urogynecology') ) OR ( CONTAINS(#(division),'Maternal-Fetal Medicine') ) OR ( CONTAINS(#(division),'Reproductive Endocrinology and Infertility') ) OR ( CONTAINS(#(division),'Reproductive Research') )"]Division<br>[wpv-post-taxonomy type="division" format="name"]<br>[/wpv-conditional]

Here's what I would like to do.
[wpv-conditional if="( $(division) ne '' )"]Division<br>[wpv-post-taxonomy type="division" format="name"]<br>[/wpv-conditional]

#1828685

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You want the condition to pass if the post has *any* term of the specified taxonomy assigned, is that right?

You can use shortcodes in the if condition. Did you try with the same shortcode that you use to output the term(s) assigned to the post, e.g.

[wpv-conditional if="( [wpv-post-taxonomy type='division' format='name'] ne '' )"]Division<br>[wpv-post-taxonomy type="division" format="name"]<br>[/wpv-conditional]
#1828693

Thank you for sending the idea! It worked with a minor tweak. I just added the #() because it didn't work without.

[wpv-conditional if="( #([wpv-post-taxonomy type='division' format='name']) ne '' )"]Division<br>[wpv-post-taxonomy type="division" format="name"]<br>[/wpv-conditional]

Thank you again!