WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas?

PHP Source:

$args = array( 
        'child_of' => $post->ID, 
        'parent ' => $post->ID,
        'hierarchical' => 0,
        'sort_column' => 'menu_order', 
        'sort_order' => 'asc'
$mypages = get_pages( $args );

foreach( $mypages as $post )

$post_tempalte = the_page_template_part();

get_template_part( 'content' , $post_tempalte );

My $args should be correct according to the documentation, but it's totally ignoring parent and hierarchical.

My page structure is as follows:

-Child 1
-Child 2
--Child 1 to child 2
--Child 2 to child 2
-Child 3

And I only want to get child 1, child 2 and child 3.

share|improve this question
Try considering the depth option also. another solution which I found and seems to be working is $mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='‌​.$post->ID); here you can change sort_column & sort_order as per need. – Rohit Pande Nov 27 '12 at 13:03
@RohitPande depth didn't help me at all, setting child_of and parent to the same it was. – Volker E. May 9 '15 at 18:16
up vote 7 down vote accepted

Please check the parameter 'parent'. It seems there is a space after the name.

share|improve this answer
Oh god. So stupid. But thank you, that saved me some time. :) – jamietelin Nov 27 '12 at 14:45

With the parameter 'depth' of the "wp_list_pages" or the "get_pages" function, we can define how many levels do we want to retrieve. So here, I will display all the first child level of the current page.

            <?php global $post;
                    wp_list_pages( array(
                    'child_of' => $post->ID, // Only pages that are children of the current page
                    'depth' => 1 ,   // Only show one level of hierarchy
                    'sort_order' => 'asc'
share|improve this answer

Your Answer


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.