Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<?php 
 $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>
     </div>
<?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.

share|improve this question

2 Answers 2

You can keep your arguments and do

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

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

share|improve this answer

Part 1

To loops through parent pages and child pages you need a recursive funtion. Luckily goldenapples has written one: http://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:

<?php 
$args = array( 
    'post_type'=> 'people',
    'orderby' => 'menu_order',
    'posts_per_page' => -1 );
?>
share|improve this answer

Your Answer

 
discard

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.