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 3 levels deep product categories like following :


I want to get B, but don't know how to do. I can get all product categories, but don't know how to filter out.

Here the code I use to get product categories : ID, 'product_cat' );

            foreach( $product_category as $cat ):
            if( 0 == $cat->parent )
                echo $cat->name;
share|improve this question

Assuming you know the parent category ID, you can use get_terms() function.

$args = array(
     'parent' => 100 // id of the direct parent

$cats = get_terms( 'product_cat', $args );

foreach( $cats as $cat ) {
  echo $cat->name;

Here is more information on this function and additional arguments you can use. http://codex.wordpress.org/Function_Reference/get_terms

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.