I have a custom post type called 'rent', inside that custom post type I've assigned some taxonomies like building1, building2 etc, inside that taxonomies I have some terms.

Let's say I have a custom rent post in taxonomy building1 with term 1stfloor. I'd like to output on that post single page a term name and slug. I've could have easily done that using get_post_terms or something similar, but that function requires to specify taxonomy. But I would have many taxonomies for that custom post, and I don't want to make another single.php for every taxonomy.

So I thought I would somehow get the taxonomy of my post (it will always be one taxonomy), assign it to variable, and put as an arg to get_post_terms. Well you can simply achieve taxonomy of current post using get_post_terms

In my archive page I used $taxname = get_query_var( 'taxonomy' ); - which works like a charm, but it is not working on custom post single.

Anyone have an idea how I can do that?

  • Could you maybe provide a couple specific examples? Also, it sounds like a hierarchical taxonomy may be a better fit with buildings as parent terms of floors [as the child terms]. The one get_the_terms() solves it all.
    – mrwweb
    Commented Aug 20, 2014 at 17:38
  • Well, I've used your suggestion :) I had to take some more steps to make it work like earlier, but it seems it was the solution :) Thanks!
    – zel
    Commented Aug 21, 2014 at 17:19
  • you should write up an answer to your question and accept it or I can write up my recommendations as an answer. Former is preferred to the latter in this case, I think.
    – mrwweb
    Commented Aug 22, 2014 at 16:11
  • Write your recommendations please, you need a credit for solution :)
    – zel
    Commented Aug 25, 2014 at 13:43

1 Answer 1


In this specific case, it seems the multiple taxonomies have a clear hierarchical relationship.

Rather than a unique taxonomy for building 1, building 2, etc., these can all be located in a single "Buildings" taxonomy that is hierarchical like this:

  • Buildings Taxonomy:
    • Building 1
      • Floor 1
      • Floor 2
      • Floor 3
    • Building 2
      • Floor 1
      • etc.

This means that there's only ever one taxonomy to query with get_terms(). As a bonus, it makes it easy to final all posts on all floors in Building 1 or all floors in Building 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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