I've made a custom search which includes a 3 tier custom taxonomy that looks like this:

continent - country - - state

The search is formatting in the above way.

Here is my problem:

Example data:

Taxonomy name = 'locations'. Custom post type = 'firms'.

America [term_id = 1]
- United States [term_id = 2]
- - Idaho [term_id = 3]
- - New York [term_id = 4]
- - Wisconsin [term_id = 5]

So how would I go about returning results for all firms with a 'locations' taxonomy PARENT of ID = 2 (United States)?

Let's say the user selects United States in the dropdown. There will be no results because for the 'firms' custom post type, the 'locations' taxonomy selected is always drilled down as far as possible to the state level. So for example a firm with 'locations' set as New York would not show up when a user searches for 'United states', because their 'locations' taxonomy ID is 4 (state level) and NOT 2 (country level).

Hope this makes sense... I was thinking of perhaps storing country level and continent level in post_meta and conditionally adding a meta query on the search page if the selection is not state level.

Any ideas? I think this is quite an interesting problem :-)


1 Answer 1


If I'm understanding you correctly get_term_children does what you want.

$term_id = 2;
$tax_name = 'locations';
$term_child = get_term_children( $term_id, $tax_name );

Another possibility would be using get_categories, it has an child_of, taxonomy and depth parameter - the documentation on wp_list_categories, which offers pretty much the same functionality, is better.

  • This is perfect, thanks a lot. I didn't know get_term_children existed. Wordpress becomes better and better the more one uses it :-) Take care Nov 30, 2013 at 16:46
  • Pleasure! You're right the more you know the more fun is it :) As I'm far from the geniusly knowledge some others have, I'm learning something new every day too. @JoeT Nov 30, 2013 at 16:52

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.