206 posts
  • Has been part of the Envato Community for over 6 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!

2064 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
338 posts
  • Has been part of the Envato Community for over 4 years
  • Located in United Kingdom
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+3 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

2064 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 6 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by