Assume the following custom taxonomy structure:

  • USA
    • California
      • Los Angeles
      • San Francisco
      • Oakland
    • New York
      • New York
      • Buffalo
      • Rochester

Note: It's just sample data, so don't bother to correct it!

Now, assume the following custom post type data:

  • Some posts will be country-wide, so they will only be assigned to the USA category.
  • Some posts will only be valid in certain states, so they will get assigned only those categories, eg. California or New York.
  • Some posts will only be valid in certain cities, so they will get assigned only to those categories, eg. Los Angeles or Rochester.

I want to configure WordPress such that:

  1. If I browse to a top-level category (eg. USA), it should show a list of posts that belong to USA as well as every descendant, eg. California, Los Angeles, New York, Rochester, etc., i.e. the whole country.
  2. If I browse to a mid-level category (eg. California), it should show the obvious list of posts belonging to that category as well as all descendants, i.e. California, Los Angeles, San Fransisco, Oakland, etc., but it should also show me all posts that are tagged with the top level, i.e. USA.
  3. If I browse to the last level category page, (eg. Buffalo), it should show me posts in Buffalo, it's parent, New York and it's grandparent, USA as well.

Is this something that can be configured from within the custom post type and/or taxonomy configuration or will it need modification of the loop? What exactly would I need to do to achieve this?

1 Answer 1


Use wp_list_categories with the taxonomy argument, it is built to create hierarchal category lists but it will also support using a custom taxonomy.


Display hierarchal categories

using this you can see their hierarchal structure.

let me know the result

  • Not sure if this will solve my problem. I'm looking at something like hooking into the loop of the custom taxonomy archive pages and adding/filtering posts into it.
    – aalaap
    Dec 17, 2018 at 16:40
  • okay let me know you are trying to do in taxonomy page or any else and also it is possible by doing hooking and filter Dec 18, 2018 at 5:55
  • It will be a taxonomy page.For eg., example.com/usa or example.com/usa/california. By default, these pages only show the posts contained within that particular category as well as it's children. I want to effectively reverse it, so i see the posts in the parent categories too.
    – aalaap
    Dec 18, 2018 at 11:37

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.