Skip Navigation

[Resolved] wpv-conditional if=”( has_term(‘auteurs’, null) ne ‘0’ )”

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

Problem:
The user would like to display content only if the post is assigned a taxonomy term.

Solution:
We can check if the post taxonomy term is not equal to an empty screen ('')

[wpv-conditional if="( '[wpv-post-taxonomy type='auteurs' format='slug']' ne '' )"]<p class="auteurs">Auteurs : [wpv-post-taxonomy type="auteur"]</p>[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153472

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
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: Africa/Casablanca (GMT+01:00)

This topic contains 5 replies, has 2 voices.

Last updated by romanB-3 4 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#1581033

Hello,

I have build this

[wpv-conditional if="( has_term('auteurs', null) ne '0' )"]<p class="auteurs">Auteurs : [wpv-post-taxonomy type="auteur"]</p>[/wpv-conditional]

in order to display content only if the taxonomy "auteurs" is not empty.

But it doesn't seem to work, and always return nothing, as if it was always empty (which it's not).

I have added the has_term function to toolset settings in conditional section with no result.

Thank you.

#1581279

Hello and thank you for contacting the Toolset support.

I believe that you are not using has_term the correct way, you need to pass the term to the function instead of the taxonomy. Check the function documentation https://developer.wordpress.org/reference/functions/has_term/

I suggest using:

[wpv-conditional if="( '[wpv-post-taxonomy type='auteurs']' ne '' )"]<p class="auteurs">Auteurs : [wpv-post-taxonomy type="auteur"]</p>[/wpv-conditional]

I am not sure what is the slug of your taxonomy ('auteurs' or 'auteur'), edit the code to have [wpv-post-taxonomy type="taxonomy-slug"]

I hope this helps. Let me know if you have any questions.

#1581307

Well I'm sorry but I still can't make this work.
My taxonomy slug is "auteur".
Here is what I got on a single post template :

    [wpv-conditional if="( '[wpv-post-taxonomy type='auteur']' ne '' )"]<p class="auteurs">Auteurs : [wpv-post-taxonomy type="auteur"]</p>[/wpv-conditional]
    [wpv-conditional if="( '[wpv-post-taxonomy type='auteur']' eq '' )"]Pas d'auteur associé à cet article.[/wpv-conditional]

On both pages with terms and pages without terms, nothing is displayed.

#1581321

Please allow me temporary access to your admin area to check this further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1581417

I added format='slug' to the shortcode and it fixed the issue.

[wpv-post-taxonomy type='auteur' format='slug']

https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153472

Sorry for not suggesting that in my previous reply.

#1581419

Thank you very much ; works like a charm.
My issue is resolved now. Thank you!