Skip Navigation

[Resolved] Check if a post has a specific Term assigned

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

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

Problem:
How can I check if a Post in a Views Loop has a certain Taxonomy term assigned, so to use that in a HTML conditional to display (or not) data according wether the post has a term or not?

Solution:
To evaluate if a Post has a certain Term assigned, you need to use a special Conditional:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/ > Checking if a post has a specific term assigned

This support ticket is created 7 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by ryanM-9 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#482086
Screen Shot 2017-01-25 at 21.54.20.png

I am trying to:Using this

[wpv-if evaluate="'[wpv-post-taxonomy type='category' format='text' show='slug']' eq 'player-care'"] [wpv-post-body view_template="info-graphic-player-care"] [/wpv-if]

I'm trying to include this section within a template if the post has the category 'player-care' selected ... but it doesn't work if the post has other categories selected as well?

I visited this URL: hidden link

I expected to see: the template shouldn't be included here as it doesn't have this category selected

Instead, I got: the template is added

#482250

To evaluate if a Post has a certain Term assigned, you need to use a special Conditional:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/ > Checking if a post has a specific term assigned

#482458

Thank you, works great.

This was the final code I used incase it helps anyone else..

[wpv-conditional if="( has_term('player-care', 'category', null) eq '1' )" ]
[wpv-post-body view_template="info-graphic-player-care"] 
[/wpv-conditional]

The forum ‘Types Community Support’ is closed to new topics and replies.