• I’m attempting to generate an RSS feed with static pages. As part of the code, I have:
    $posts = query_posts('post_type=page&post_parent=56');
    This accurately shows me children of page 56. However, I’d like to get the grandchildren of page 56. What can I add to generate this?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    $gen1_ids = 56;
    $gen2 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen2_ids = implode($gen2,', ');
    $gen3 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen2_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen3_ids = implode($gen3,', ');
    $args=array(
      'post__in' => $gen3,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Pages grandchild pages of id 56' ;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    ?>

    Thanks MichaelH!
    That helped out a lot.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts grandchildren of static pages’ is closed to new replies.