Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the following code to display the term for a specified taxonomy:

$terms = get_terms( "book_review" );
$category = $terms[0]->name;

However I want to display the term for whatever the currently displayed taxonomy is, rather than specifying a particular taxonomy. Basically what I'm wanting is a way to replicate the functionality of get_the_category, but for the current taxonomy instead of the current category. I'm trying to display this on a single custom post type page (single-custom_post_type_name.php)

share|improve this question
    
What context? The taxonomy page (URL=/your-taxonomy/your-term/), or somewhere else? –  MikeSchinkel Apr 5 '11 at 1:30
    
I updated the question with the context. –  Industrial Themes Apr 5 '11 at 13:24
add comment

1 Answer

up vote 2 down vote accepted

You can use get_queried_object to get the term name.

<?php if( is_tax() ) {
    global $wp_query;
    $term = $wp_query->get_queried_object();
    $title= $term->name;

}  ?>

To display: <?php echo $title; ?>

If your on a taxonomy archive page you can use:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

Then to display the term: <?php echo $term->name; ?>

The following properties are available for the $term object:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent -count
share|improve this answer
add comment

Your Answer

 
discard

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.