I'm trying to use query_posts to list all descendants of a page ID. Using post_parent only lists the first-level children.

This Trac ticket seems to address it: http://core.trac.wordpress.org/ticket/5742, but I don't understand it -- post_parent only lists the first-level children.

    query_posts( array(
    'post_parent' => 58, // Only shows posts that are direct children of the Machinery page. I want all descendants.
    //'child_of' => 58, // When used, shows posts filterd by taxonomy and term, but not filtered by child of ID 58. Acutally omits direct child of 58 but shows grandchild.
    'post_status' => 'any',
    'post_type' => 'any',
    'taxonomy' => 'industries',
    'term' => 'dairy'
<?php if ( have_posts() ) : ?>
    <h4>Dairy Machinery</h4>
        <?php while (have_posts()) : the_post(); ?>    
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
<?php endif; wp_reset_query(); ?>

How do I get query_posts to list all descendants of a page ID?

1 Answer 1


If you don't have to use query_posts() then this is one method:

function my_menu() {
    global $post;

        // will display the subpages of this top level page
        $children = wp_list_pages( array( 'title_li' => '', 'child_of' => $post->ID, 'echo' => 0 ) );
    } elseif($post->ancestors){
        // diplays only the subpages of parent level
        $ancestors = end($post->ancestors);
        $children = wp_list_pages( array( 'title_li' => '', 'child_of' => $ancestors, 'echo' => 0 ) );
    } else {
        // diplays all pages
        $children = wp_list_pages( array( 'title_li' => '', 'echo' => 0 ) );

    if ($children) {
        echo '<ul id="my-menu">';
        echo $children;
        echo '</ul>';

  • Thanks for the help. Your code shows the descendants of the current top-level page. What I need is the descendants of a specific page ID, then only show those pages that have a certain taxonomy term. Any ideas? I can get the pages like this: <?php $children = wp_list_pages("title_li=&child_of=58&echo=0"); ?> But then how do I filter them to show only the ones with: 'taxonomy' => 'industries', 'term' => 'dairy'
    – mikedev
    Apr 13, 2012 at 18:58

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.