Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Display custom taxonomy on a page

Sorry this is simple stupid question, but I can't get it to work. There must be some logical part I'm missing.

Using Custom Post Type UI.

  1. I've create a custom post type, called team.
  2. I've create a custom taxonomy jobtitle and attached it to team. And it shows up and I can add to it.
  3. I've created a page named single-team.php put display the post types content. And it works.
  4. But how do I display the current taxonomy associated with each post. It could be manager or administration.

I've tired the codex and have come across get_the_terms but clearly I'm doing it way wrong.

get_the_terms( $post->ID, 'jobtitle' ); But I even can see that it lacks something.

I don't want to display the whole list of taxonomies ( for now) just the one or two that might be associated with a spectic team member (post).

Hope it make sense.

Doru Marginean
Doru Marginean
2,290 Points

Hi Christian Steen Jรธrgensen,

The example you provided using get_the_terms() returns an object and you need to construct the HTML. I think it will be easier for you to use get_the_term_list().

<?php
/**
 * Basic example
 *
 * @return string HTML of taxonomy terms
 */
echo get_the_term_list( $post->ID, 'jobtitle', 'Job titles: ', ', ' );
?>

More info here: https://codex.wordpress.org/Function_Reference/get_the_term_list