Title: Child Pages Question
Last modified: August 20, 2016

---

# Child Pages Question

 *  [foochuck](https://wordpress.org/support/users/foochuck/)
 * (@foochuck)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/)
 * I’m using the following code to pull in data from child pages into my parent 
   page:
 *     ```
       <?php
       		$mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=asc');
       		foreach( $mypages as $page ) :	setup_postdata($page); ?>
       		<div class="item">
       			<div class="thumbnail"><a href="<?php echo get_page_link($page->ID) ?>"><?php echo get_the_post_thumbnail($page->ID, 'full', array('alt' => $page->post_title, 'title' => $page->post_title));?></a></div>
       			<h1><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?> >></a></h1>
       			<p><?php echo(get_post_meta($page->ID, excerpt, true)); ?></p>
       ```
   
 * This works fine. However I have added another level of child pages to the mix.
 * So here’s a map:
 * Parent -> Child -> Grandchild
 * The parent page is now pulling in data from child & grandchild pages when I run
   the code above in my page template.
 * Is there a way to force the code to check only and child and not the “grandchildren”
   as well?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/#post-2201499)
 * use the ‘parent’ parameter with/instead of the ‘child_of’ parameter:
 * [http://codex.wordpress.org/Function_Reference/get_pages](http://codex.wordpress.org/Function_Reference/get_pages)
 *  Thread Starter [foochuck](https://wordpress.org/support/users/foochuck/)
 * (@foochuck)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/#post-2201520)
 * Please note that I’m using this on the parent page template. Will it still work
   if I change it to ‘child_of’ ?
 *  Thread Starter [foochuck](https://wordpress.org/support/users/foochuck/)
 * (@foochuck)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/#post-2201521)
 * I also noticed that ‘child_of’ will pull the grandchildren as well from the codex
   description:
 * child_of
    (integer) Displays the sub-pages of a single Page only; uses the ID
   for a Page as the value. Defaults to 0 (displays all Pages). Note that the child_of
   parameter will also fetch “grandchildren” of the given ID, not just direct descendants.
   0 – default, no child_of restriction
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/#post-2201531)
 * i was obviously referring to:
 * > parent
   >  (integer) Displays those pages that have this ID as a parent. Defaults
   > to -1 (displays all Pages regardless of parent). Note that this can be used
   > to limit the ‘depth’ of the child_of parameter, so only one generation of descendants
   > might be retrieved. **You must use this in conjuction with the child_of parameter.
   > Feed it the same ID.** Also note that the hierarchical parameter must be set
   > to 0 (false) — which is not default — or else no results will be returned for
   > any page other than the root (ID=0). -1 – default, no parent restriction 0 –
   > returns all top level pages
 * (bold added by me)
    [http://codex.wordpress.org/Function_Reference/get_pages](http://codex.wordpress.org/Function_Reference/get_pages)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Child Pages Question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/child-pages-question/#post-2201531)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
