Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to echo my hierarchical taxonomies parents which i used in my posts. I've see answers about that, but no one didn't help me. Now i using <?php the_terms( $post->ID, 'mytaxname', '', ' / ', ' ' ); ?> to get all taxonomies. But i want to get only parents of used tax's. But i need simplest answer, because i'm not good at PHP. Hope to get answer. Thanks a lot.

share|improve this question

1 Answer

Try this:

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

  echo $parent->name;
?>

You have to get the current term slug and then use get_term by the slug and then echo the name.

share|improve this answer
Thank you for answer. But this code doesn't echo anything. I changed 'taxonomy' to my taxonomy name, nothing happens :( – Ziya Aliyev Jun 28 '12 at 10:40
I dont think you need to change taxonomy to something else. – Pontus Abrahamsson Jun 28 '12 at 11:11
Look, my hierarchical taxonomy name (slug) is called "Role". How WordPress must recognize, which taxonomy i want to echo?) – Ziya Aliyev Jun 28 '12 at 11:44
Maybe i must use $post->ID somewhere? – Ziya Aliyev Jun 28 '12 at 11:53
this code doesn't echo anything :( – Ziya Aliyev Jun 28 '12 at 12:15
show 4 more comments

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.