Skip Navigation

[Resolved] Conditional display using Taxonomy Term Fields

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

Problem:
How to use taxonomy term fields in a conditional test on a taxonomy archive page so that the field can be tested to see if it has a value set before trying to display it?

Solution:
The usual format for custom fields in wpv-conditional shortcodes doesn't work for term fields on a taxonomy archive page, and it is necessary to insert the full types shortcode in the if condition, such as in this example:

[wpv-conditional if="( '[types termmeta='hex-colour' output='raw'][/types]' ne '' )"]
<p>We have a hex value</p>
[/wpv-conditional]
This support ticket is created 6 years, 9 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Author
Posts
#740061
01.jpg
03.PNG
02.PNG

-- Tell us what you are trying to do?

Display (or not) a content depending of a series of taxonomy term field.

On my archive page result displaying a specific VFX Studio, if there is no logo or link or description or video [...] set for this "vfx-studio" taxonomy, I don't want to display anything.

-- Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific
... but no success so far.

-- Is there a similar example that we can see?
n/a

-- What is the link to your site?
What I want (all fields set) : hidden link
What I want to avoid (no fields set): hidden link

thank you!

#743618

Nigel
Supporter

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

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

Hi Bruno

It seems that for term fields you can't readily insert them using the GUI, and the same format used for Types post fields (with the $ sign) doesn't work.

So I tried using the full version of the types shortcode used to output the term field itself, and that worked.

So here is a simple example from one of my test sites, where I have a "colour" taxonomy and the terms have a "hex-value" term field.

<p>Here is the hex value: [types termmeta='hex-colour' output='raw'][/types]</p>
[wpv-conditional if="( '[types termmeta='hex-colour' output='raw'][/types]' ne '' )"]
<p>We have a hex value</p>
[/wpv-conditional]

Do you want to try the same?

#746890

Thanks Nigel! That's exactly what I needed! Too bad it's not available directly in the GUI... hopefully in a future update!
Cheers.