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'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?

share|improve this question

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>';

share|improve this answer
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 '12 at 18:58

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.