Skip Navigation

[Resolved] Conditional display if current term page is from a specific taxonomy

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

Problem: I have an archive assigned to multiple taxonomies. I would like to display some information conditionally depending on where the archive is displayed, per taxonomy or per term.

Solution: Use the is_tax function built-in to WordPress to determine the current archive location. Be sure to register it in Toolset > Settings > Front-end content > Functions inside conditional evaluations, and be sure to supply all optional arguments to the function like so:

[wpv-conditional if="( is_tax('auteur', null) eq '1' )"]
... this is the auteur taxonomy archive...
[/wpv-conditional]

Relevant Documentation:
https://codex.wordpress.org/Conditional_Tags#is_tax

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

Assisted by: Christian Cox.

Author
Posts
#1577091

Hello,
I have an Archive page applied to several taxonomies.
In it, I'd like to use the conditional display in order to show or hide specific informations depending on the current term's taxonomy.
But I still haven't found any shortcode that would allow me to do this. Is there one ?
Thank you.

#1577653

There is a built-in WordPress function called is_tax that you can use for this purpose in a conditional. You must register is_tax in Toolset > Settings > Front-end Content > Functions inside conditional evaluations to use it in a conditional. Here is the documentation for is_tax:
https://codex.wordpress.org/Conditional_Tags#is_tax

This would be true if the category taxonomy archive is being displayed:

is_tax('category')
#1577737

Thank you very much ; this is it !

#1577739

Well... in fact it doesn't seem to work 🙁

Wouldn't this be the syntax ?

[wpv-conditional if="( $(is_tax('auteur')) ne 'true' )"]<div class="form-group">
	<label for="wpv-auteur">[wpml-string context="wpv-views"]Auteurs[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="auteur" type="multi-select" url_param="wpv-auteur"]
</div>[/wpv-conditional]
#1578595

It should be like this:

[wpv-conditional if="( is_tax('auteur') )"]
...

...but it doesn't seem to be working in my local tests. Let me ask 2nd tier for some additional information here.

#1579921

I forgot about this:
This is important because you should always set the optional parameters for your functions when you use them inside wpv-conditional shortcodes. If you do not set the optional parameters in your function, they will be passed as those described above, so it may have unexpected results.
From the documentation here: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/#custom-functions

To fix the code, you must include null as the 2nd parameter of the is_tax function:

[wpv-conditional if="( is_tax('auteur', null) eq '1' )"]
... this is the auteur taxonomy archive...
[/wpv-conditional]
#1579927

Thank you very much ; it works great now !
My issue is resolved now. Thank you!