WordPress Version: 4.1
/**
* Retrieve child pages from list of pages matching page ID.
*
* Matches against the pages parameter against the page ID. Also matches all
* children for the same to retrieve all children of a page. Does not make any
* SQL queries to get the children.
*
* @since 1.5.1
*
* @param int $page_id Page ID.
* @param array $pages List of pages' objects.
* @return array List of page children.
*/
function get_page_children($page_id, $pages)
{
$page_list = array();
foreach ((array) $pages as $page) {
if ($page->post_parent == $page_id) {
$page_list[] = $page;
if ($children = get_page_children($page->ID, $pages)) {
$page_list = array_merge($page_list, $children);
}
}
}
return $page_list;
}