Skip Navigation

[Resolved] Conditionally displaying tags on a custom post

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

Problem:
Conditionally displaying tags on a custom post

Solution:
You can use [wpv-conditional] shortcode to check post tag and display output conditionally.

[wpv-conditional if="( '[wpv-post-taxonomy type='post_tag'  format='name']' ne '' )"]
 
<p>Keywords: [wpv-post-taxonomy type="post_tag"]</p>
 
[/wpv-conditional]

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/conditionally-displaying-tags-on-a-custom-post/#post-917304

Relevant Documentation:

This support ticket is created 6 years, 6 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
- 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 2 replies, has 2 voices.

Last updated by josephQ 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#917125
keywords.png

Tell us what you are trying to do? I'm trying to conditionally display a list of tags on a custom post. I'd like it to say "Keywords: tag1, tag2, tag3," etc. But I don't want the word "Keywords:" to appear if the post has no tags.

I've created a Template Layout with a cell with conditional output like so:

[wpv-conditional if="( '[wpv-post-taxonomy]' ne '' )"]
<p>Keywords: [wpv-post-taxonomy type="post_tag"]</p>
[/wpv-conditional]

This doesn't work. The word "Keywords:" does appear when the post has no tags (see hidden link). I also tried the following snippet of code:

[wpv-conditional if="( '[wpv-post-taxonomy type=\'post_tag\']' ne '' )"]
<p>Keywords: [wpv-post-taxonomy type="post_tag"]</p>
[/wpv-conditional]

This doesn't work, either. The word "Keywords:" does appear when the post has no tags.

I'd also like to display the word "Keyword" if there is only one tag and "Keywords" if there is more than one tag. Is there a way to count the number of tags?

#917304

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - could you please try to use following conditional shortcode and try to resolve your issue:

[wpv-conditional if="( '[wpv-post-taxonomy type='post_tag'  format='name']' ne '' )"]

<p>Keywords: [wpv-post-taxonomy type="post_tag"]</p>

[/wpv-conditional]
#917549

Thanks, Minesh! I didn't know how to handle the nested single quotes. This did the trick!