• I would like to display a list of grand child with wp_query.

    This is what I have for display child from the parent.

    <?php
    $page_id = $parent_id;
    $args=array(
      'post_parent' => $page_id,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 100,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <div class="main_post_listing2"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">&rsaquo;&nbsp;<?php the_title(); ?></a>&nbsp;&nbsp; &nbsp;&nbsp;<?php the_time('M d, Y') ?>
        </div><?php
      endwhile;
    }
    
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    </div>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Store an array of post ids in that loop you show, then in another qyery loop use that array with the ‘post__in’ argument.

    Thread Starter radiofranky

    (@radiofranky)

    Hi,
    I understand what you mean, but php is not my forte.
    Could you show me how to code it?

    thanks

    Thread Starter radiofranky

    (@radiofranky)

    Hi Michael,
    this is what I’m trying to achieve.

    I have list of video titles set as parent and I used the code shown above to list all the parent titles.

    But each parent page has sub-pages assigned to it. For example, for this particular video ABC, I have 5 sub-pages.

    I want to be able to show like this.

    video title    parts    date added
    abc video    1, 2, 3, 4,   16 June, 2010

    thanks for your help.

    Thread Starter radiofranky

    (@radiofranky)

    I got it working but if you have better way, please let me know. thanks

    <?php $parent_id = get_the_id($post->post_parent); ?>
    <?php
    $page_id = $parent_id; ?>
    
    <?php $args=array(
      'post_parent' => $page_id,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 100,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <?php $parentid=array(post_id); ?>
    	<div class="main_post_listing2"><a href="<?php the_permalink() ?>" target="_blank"rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">&rsaquo;&nbsp;<?php the_title(); ?></a>&nbsp;&nbsp;
    	<?php
    
      $children = wp_list_pages("depth=1&title_li=&child_of=".$post->ID."&echo=0&sort_column=post_date");
      $titlenamer = get_the_title($post->post_parent);  ?>
       <ul class="show_sub_page_main"><?php  echo $children; ?></ul>&nbsp;&nbsp;<?php the_time('M d, Y') ?> </div>
       <?php
      endwhile;
    }
    
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>  
    
    </div>

    That’s a nice solution!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to display grandchild with wp_query?’ is closed to new replies.