I has custom field 'People' and I have parent pages(post types) and child pages (post types). This is my code:

 $args = array( 
'post_type'=> 'people',
'posts_per_page' => -1,
$loop = new WP_Query( $args );
    while ( $loop->have_posts() ) { ?>
    <?php $loop->the_post();?>
     <div class="title">    
         <a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php } ?>

I need display this custom post types in hierarchical order. For example:

First parent post type
   - first child of first parent post type
   -second child of first parent post type
Second parent post type
   -first child of second parent post type

But by default this posts displayed in other by time of publish. Any ideas, how resolved this problem?

Thanks all.

2 Answers 2


Part 1

To loops through parent pages and child pages you need a recursive funtion. Luckily goldenapples has written one: https://wordpress.stackexchange.com/a/13678/1878

Part 2

That takes care of that but you still want to be able to order it, so WordPress allows us to set a Page Order. If you go into the edit page screen you will see under the Attributes box a spot for order. You can also set the order in the quick edit screen. Page Quick Edit Screen

And then we need to tell the loop for orderby that order:

$args = array( 
    'post_type'=> 'people',
    'orderby' => 'menu_order',
    'posts_per_page' => -1 );

You can keep your arguments and do

$args = array(
  'title_li'=> __('People')
wp_list_pages( $args );

post_type is an acceptable argument and will take care of the recursion for you.

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.