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

Well, this should be pretty simple, however I couldn't find answer anywhere on the web. all answers I found were close but no exactly what I needed. what I need is to display just the current term of a custom post type I am in. not all the terms just one! (the relevant one)

this is what I'm using but it displays ALL the terms which is not good for me:

$taxonomy = 'genre';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
if ($terms) {
  foreach($terms as $term) {
    echo $term->name;

remember - I would like to display it in my single post type template can anyone suggest? thanks

share|improve this question
up vote 4 down vote accepted

Ok, so I finally found what I needed here: How to get current term in my custom taxonomy in WordPress?

the last update at the bottom courtesy of @user3208:

<?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
} } ?>

That solved my issue! Thanks

share|improve this answer
Thank you very much for your answer! – Anahit Ghazaryan Jun 30 '15 at 5:38

You should use wp_get_post_terms instead.

$terms = wp_get_post_terms( $post_id, $taxonomy, $args );

get_terms will give you all the terms present in a taxonomy.


global $post;
$terms = wp_get_post_terms( $post->ID, 'genre');
print_r($terms); #displays the output
share|improve this answer
I am trying but it's not working. do I have to pass any vars into the function? can you specify how should I implement it in my code? Thanks – gil hamer Mar 1 '13 at 12:46
If you are in the WordPress Loop, you can use get_the_ID() instead of $post_id. For $taxonomy, you need to add the name of the taxonomy you're using. $args isn't necessary. – RRikesh Mar 1 '13 at 16:14
It's definitely outside the loop! just cant get it to work.. can you suggest how to implement it outside the loop? if necassary I will post the whole code. Thanks – gil hamer Mar 1 '13 at 16:28
Then you need to add global $post; and then use $post->ID to get the post ID. – RRikesh Mar 1 '13 at 16:32
can you show me an example using my code above? I am not that programmer. I'll appreciate it. Thanks – gil hamer Mar 1 '13 at 16:35

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.