Skip Navigation

[Resolved] Conditional to check if current post has any terms from a custom taxonomy

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 1 year, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2702289

I am trying to output markup in a single post template only when the current post has at least on term of a custom taxonomy. The conditional output GUI does not seem to have an option for this. So I have tried the suggested shortcode shared here: https://toolset.com/forums/topic/conditional-to-test-for-taxonomy-results/ as

[wpv-conditional if="('has_term('','thematic-focus')' eq '1' )" debug="true"]Thematic focus: [wpv-post-taxonomy type="thematic-focus" format="name"][/wpv-conditional]

Where thematic-focus is the slug of the custom taxonomy. The output is below:
```
####################
wpv-conditional attributes
####################
Array
(
[if] => ('has_term('','thematic-focus')' = '1' )
[debug] => true
)
####################
Debug information
####################
--------------------
Original expression: ('has_term('','thematic-focus')' = '1' )
--------------------
After replacing 1 general variables and comparing strings: ('has_term('','thematic-focus')' = 1 )
Comparing ) to 1
```
Is there something I am doing wrong, or is there a better way to do this now?

#2702344

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Here is the Doc that shows how you should add the conditional statement to check at least one term assigned:
- https://toolset.com/documentation/legacy-features/views-plugin/displaying-taxonomies-conditionally/#one

For example:

[wpv-conditional if="('[wpv-post-taxonomy type='thematic-focus' format='slug']' ne '')"]
Thematic focus: [wpv-post-taxonomy type="thematic-focus" format="name"]
[/wpv-conditional]
#2702360

Thanks, missed this in the documentation.