WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'm using woocommerce on my theme, and it comes with a proudct_cat term as a defualt catagory on the shop proudct. I need to show on every proudct_cat archive its direct child and the sub-tems, but not the sub terms child.

I tried:

        <?php $thispage = $wp_query->post; wp_list_categories("taxonomy=product_cat&term=". $term->slug."&title_li=&child_of=".$thispage->slug);?>

and it returned all proudct_cat as ul and the sub-term of the archive im in, but not the archive's children.

I tried:

global $post;
        $terms = get_the_terms( $post->ID, 'product_cat');
        foreach ( $terms as $term )
        $currentID = get_the_ID();
            'term' => $term->slug,

        $my_query = new WP_Query( $args ); 

        <?php if ( $my_query->have_posts() ): ?>
        <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
            <li> <a href="<?php the_permalink(); ?>" id="booklink"><?php the_title();?></a></li>
        <?php endwhile; ?>
    <?php endif; ?>

and it returned all the the current archive's children and the sub-terms children without the sub-term it self.

So i tried :

        $term_id = $terms;
        $taxonomy_name = 'product_cat';
        $termchildren = get_term_children( $term_id, $taxonomy_name );

        echo '<ul>';
        foreach ( $termchildren as $child ) {
            $term = get_term_by( 'id', $child, $taxonomy_name );
            echo '<li><a href="' . get_term_link( $term->name, $taxonomy_name ) . '">' . $term->name . '</a></li>';
        echo '</ul>';

and it returned nothing.

I'm Speechless. anyone have a clue?

*sorry for my poor English

share|improve this question

Try get_terms( 'product_cat', 'parent=' . get_queried_object_id() )

Update: Re-read your question, think I have a better idea:

<ul class="categories">

                'child_of' => get_queried_object_id(),
                'taxonomy' => 'product_cat',
                'title_li' => '',
                   'depth' => 2,

share|improve this answer
got nothing.... – AmitR Jul 11 '13 at 21:58
Check out my update. – TheDeadMedic Jul 11 '13 at 23:02
Ok, cool... but it returns only the current sub term. – AmitR Jul 11 '13 at 23:29

got an idea... if this returns only the sub term: wp_list_categories( array('child_of' => get_queried_object_id(),'taxonomy' => 'product_cat','title_li' => '','depth' => 1, 'show_option_none'=> ''));

maybe i can exacude all of its children in a guery args and then call the wp_list_categories. tried: $terms = get_the_terms( $post->ID, 'product_cat'); foreach ( $terms as $term ) $currentID = get_the_ID(); $args=array( 'taxonomy'=>'product_cat', 'term' => $term->slug, 'exclude '=> array('child_of' => get_queried_object_id()) ); $my_query = new WP_Query( $args );?>

but it returns only the sub-term children, not the the proudct_cat children...


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.