206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

I cannot seem to find the code to display what category (custom taxonomy) a post belongs to in my template file. Something that is like the_category(', ') but for custom post type terms. Seems like it should be easy but I just can’t seem to get it.

Help is much appreciated!

2058 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
Landonw says
329 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
PaulWinslow says

I think the_terms() is what you’re looking for. Apologies if I’ve misread your post.

http://codex.wordpress.org/Function_Reference/the_terms

The the_terms() function is used to return a list of terms for a given taxonomy of a specific post.

You should be able to ignore the last 3 parameters, just passing the first 2 should be fine – the post’s ID and the name of your custom taxonomy.

Try this..

<?php the_terms( $post?>ID, 'taxonomy_name', '', '', '' ); ?>

edit – for some reason there’s a question mark showing up above, it’s supposed to be the following without spaces..

$ post – > ID

2058 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
Landonw says

@Paul: Oh! I see the difference. the_terms() displays it for you, but wp_get_post_terms() just returns the data.

206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

Ah… I am so stupid sometimes… I kept putting the post type instead of the taxonomy in the args. Duh… no wonder. Took a post to clear my brain I guess. This community is awesome! thank you both.

by
by
by
by
by
by