WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to display the current term in my custom taxonomy in a single post.


  • My custom taxonomy is products and term of them is product-1, product-2 and products-3.
  • My post is assigned to product-2
  • And I want to print the current products = products-2 in my post

In fact, I need a function like WordPress's the_category(); but for my taxonomy like the_customtaxonomy();


in facts i know i need to get id of this becuse i need to show a icon for this in my single , for example a function like the_category_ID();

share|improve this question

migrated from stackoverflow.com Feb 15 '11 at 16:07

This question came from our site for professional and enthusiast programmers.

You can use get_the_term_list():


Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.


<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
share|improve this answer
the only problem with get_the_term_list is that it wraps the terms in html. use wp_get_object_terms() to get an array of terms back – anu Feb 15 '11 at 16:38
In that case you could use get_the_terms instead. – t31os Feb 15 '11 at 16:49
@anu, Well, he did say he wanted a function like the_category, which also wraps the terms in HTML. – user2370 Feb 15 '11 at 18:08

I found it:

//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

$taxonomy     = 'genre';
$orderby      = 'name'; 
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title

<?php wp_list_categories( $args ); ?>

It gets all terms in my custom taxonomy and I need to get current term.

share|improve this answer
For your images, you should use CSS pseudo selectors to inject your icons. – Brian Fegter Sep 21 '11 at 13:30

tanks for answer from my friend , i find it for show slug of my taxonomy

 $terms = get_terms('my-taxonomy-name');
 foreach ( $terms as $term ) {
 echo $term->slug.' ';

and but it return all term in my taxonomy and i need to return current term in my taxonomy ..


i finaly find this and add if for empty terms and works

<?php   // Get terms for post
 $terms = get_the_terms( $post->ID , 'oil' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->slug ;
 // Get rid of the other data stored in the object, since it's not needed
} } ?>
share|improve this answer

You need to use wp_get_object_terms()

wp_get_object_terms( $object_ids, $taxonomies, $args )

  • $object_ids: string or array ids for the objects you want to get terms for
  • $taxonomies: string or array of taxonomies
share|improve this answer
echo get_the_term_list( get_the_ID(), 'tax_name', 'Product:' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.