Skip Navigation

[Resolved] Displaying text conditionally depending on the taxonomy.

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Stefan_H2035 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1194821
Sake Type Lable.jpg

Tell us what you are trying to do?
I am using Divi Builder where I have created a template for a single product. I have inserted a conditional to display a custom taxonomy in relation to a category as shown below.

{!{wpv-conditional if="( $(product_categories) eq 'Sake' )"}!} {!{wpv-post-taxonomy type="sake-type"}!}

My question is how do I also conditionally display text which is the label for the taxonomy that I am displaying. Note that I have gotten the conditional to work and display the taxonomy but I can't do the same for the text (label). See picture attached.

Sakey Type: {!{wpv-post-taxonomy type="sake-type"}!}

Is there any documentation that you are following?

I have read the forums but I can't find a solution.

Is there a similar example that we can see?

What is the link to your site?

hidden link

#1195137

Hi, there's no shortcode to display a Taxonomy label, so you should do something like this:

{!{wpv-conditional if="( $(product_categories) eq 'Sake' )"}!} 
  Sake type: {!{wpv-post-taxonomy type="sake-type"}!}
{!{/wpv-conditional}!}
{!{wpv-conditional if="( $(product_categories) eq 'Whisky' )"}!} 
  Whisky type: {!{wpv-post-taxonomy type="whisky-type"}!}
{!{/wpv-conditional}!}
{!{wpv-conditional if="( $(product_categories) eq 'Vodka' )"}!} 
  Vodka type: {!{wpv-post-taxonomy type="vodka-type"}!}
{!{/wpv-conditional}!}
#1196493

Hi, Thanks. But when I add the ending code {!{/wpv-conditional}!} to the end, the category does not appear. But when I remove it, the remaining works and displays with the label.

#1196811

Okay I see now, the $(product_categories) syntax is not correct. The $(slug) syntax should only be used for testing custom field values, but you're trying to use it with a taxonomy term. This won't work. Instead, you should use "has_term" as described here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific

If you are using WooCommerce, the WC Product Categories taxonomy slug is "product_cat", so your code would look like this:

{!{wpv-conditional if="( has_term('Sake', 'product_cat', null) eq '1' )"}!} 
  Sake type: {!{wpv-post-taxonomy type="sake-type"}!}
{!{/wpv-conditional}!}

Be sure to register has_term in Toolset Settings, as described in that document.

#1196846

Hi, I registered the has_term in the settings and used the recommended code but it didn't work. I played adjusted it a bit as follows:

{!{wpv-conditional if="( has_term('Sake', 'product_cat') eq 'Sake' )"}!}Sake Types: {!{/wpv-conditional}!}{!{wpv-post-taxonomy type="sake-type"}!}

This produced the text for the Sake Type, however, the Label Sake Types did not appear. I then shifted the {!{/wpv-conditional}!} to the end as follows:

{!{wpv-conditional if="( has_term('Sake', 'product_cat') eq 'Sake' )"}!}Sake Types: {!{wpv-post-taxonomy type="sake-type"}!}{!{/wpv-conditional}!}

This did not work as well and produced neither the label or the Sake Type.

#1196850

Got it to work with this.

{!{wpv-conditional if="( has_term('Sake', 'product_cat', null) eq '1' )"}!} Sake type: {!{/wpv-conditional}!} {!{wpv-post-taxonomy type="sake-type"}!}

Thanks for the help!

#1196851

My issue is resolved now. Thank you!