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:
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.
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.
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?
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:
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.
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.
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?
custom-taxonomy
loop
hierarchical
Share
Improve this question
asked Dec 17, 2018 at 10:57
aalaapaalaap75411 gold badge88 silver badges1818 bronze badges
Add a comment
|
1 Answer
1
Reset to default
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.
Example:
Display hierarchal categories
using this you can see their hierarchal structure.