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 have a post type called venues, and each post type has a list of values to choose from in my custom taxonomy 'location'.


  • London (top level)
    • West London (2nd level)
    • North London (2nd level)
    • East London (2nd level)
      • Hackney etc.. (3rd level)

I would like to find results that match the lowest tier of taxonomy first, if there aren't any posts, then it will get results from the next taxonomy up, and so on. Each time the venue only has 1 value on each tier of the location taxonomy.

Any help much appreciated.

One thing that may help me write the code is if I knew how to load a taxonomy value by its term_id. Or if I could somehow determine the of the current taxonomy in relation to its parents.

share|improve this question
Do you want to get these terms in SQL or PHP? For the latter see wpse_57512_count_ancestors(). – toscho Oct 31 '12 at 1:10

I was able to solve this by ordering my taxonomy values based on this post:

Custom taxonomy, get_the_terms, listing in order of parent > child

share|improve this answer

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.