I thought this would be a simple case of following the Codex but apparently not. I'm trying to display child pages of a particular page on my homepage using a custom made template. So far I've managed to display what I want in terms of the content but I can't achieve my goal which is to display child pages of one selected page.

The page I want has an ID of 37. Yet using child_of or parent it ignores it and shows every single page. Below if my code:

                    <?php $home_pages = new WP_Query(array(
                        'sort_order'    => 'DESC',
                        'sort_column'   => 'post_date',
                        'post_type'     => 'page',
                        'post_status'   => 'publish'
                        if( $home_pages->have_posts() ) : ?>
                            <?php $pages_per = 0; 
                            while( $home_pages->have_posts() && $pages_per < 6 ) : $home_pages->the_post(); ?>
                                    <?php if ( has_post_thumbnail() ) : ?>
                                        <?php the_post_thumbnail(); ?>
                                    <?php else : ?>
                                        <img src="images/noimage.png" border="0" alt="No Thumbnail" />
                                    <?php endif; ?>
                                    <a href="<?php the_permalink(); ?>" class="title"><?php the_title(); ?></a>
                                    <?php $pages_per++; ?>
                            <?php endwhile; ?>
                        <?php endif; ?>
                        <?php wp_reset_postdata(); wp_reset_query(); ?>

The code shows six pages as instructed in the loop but doesn't seem to filter out any pages. The above example doesn't use child_of and parent but that's because I tried them and it didn't work.

For reference: https://codex.wordpress.org/Function_Reference/get_pages

  • You're mixing get_pages() parameters into your WP_Query call - so what is it what you actually want to use here? Commented Apr 13, 2015 at 22:29

1 Answer 1


I figured it out. It looks as if the Codex never referenced the one parameter I needed to make it work in the Codex. I checked out this site here for a full list of parameters in the arrays http://www.billerickson.net/code/wp_query-arguments/

I needed to use post_parent and not child_of or parent. Fixed.

  • Yea, you needed to read the correct documentation, the one for WP_Query, thats all :D But, hey, you solved it! Commented Apr 13, 2015 at 22:32
  • That's true! If I hadn't of asked this question I know I'd still be stuck on it. Oh well. Hopefully someone else finds this useful too! :)
    – user69700
    Commented Apr 13, 2015 at 22:33
  • Someone usually does. Commented Apr 13, 2015 at 22:34

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.