I have in my WordPress theme, a section where I am getting child pages to display their information. This is what I have right now:
<?php
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
$staff = get_page_children(8, $all_wp_pages);
foreach($staff as $s){
$page = $s->ID;
$page_data = get_page($page);
$content = $page_data->post_content;
$content = apply_filters('the_content',$content);
$content = str_replace(']]>', ']]>', $content);
echo '<div class="row-fluid"><span class="span4">';
echo get_the_post_thumbnail( $page );
echo '</span><span class="span8">'.$content.'</span></div>';
}
?>
I have five child pages that should be showing up, but only three are returning. I used print_r on $staff to see if the other pages were even in the array, but they aren’t. I’m not sure what the problem could be.
There is nothing wrong with
get_page_children()ornew WP_Query(). By defaultWP_Queryreturns only the lastxnumber of pages created. It’s the limit imposed onWP_Query.get_page_children()simply takes the pages array returned byWP_Queryand filters the children pages from that list. According to WordPress Codex: get_page_children “…does not make any SQL queries to get the children.”To fix the issue simply use:
Your code with the fix:
Here is a helper function that you can call whenever you need to get page children
Example
You code with with the helper function