query_posts grandchildren of static pages (3 posts)

  1. laraswanson
    Posted 5 years ago #

    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!

  2. MichaelH
    Posted 5 years ago #

    $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,', ');
      '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>
    wp_reset_query();  // Restore global post data stomped by the_post().
  3. silencematters
    Posted 4 years ago #

    Thanks MichaelH!
    That helped out a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.