WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get page children

Description

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.

Usage

<?php get_page_children$page_id$pages ); ?>

Parameters

$page_id
(integer) (required) Page ID.
Default: None
$pages
(array) (required) List of pages' objects.
Default: None

Return Values

(array) 

Examples

<?php
// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1'));

// Get the page as an Object
$portfolio =  get_page_by_title('Portfolio');

// Filter through all pages and find Portfolio's children
$portfolio_children = get_page_children( $portfolio->ID, $all_wp_pages );

// echo what we get back from WP to the browser
echo '<pre>' . print_r( $portfolio_children, true ) . '</pre>';
?>

Notes

This function calls itself recursively.

Change Log

Since: 1.5.1

Source File

get_page_children() is located in wp-includes/post.php.

Related

Page Tags: get_all_page_ids(), get_ancestors(), get_page(), get_page_link(), get_page_by_path(), get_page_by_title(), get_page_children(), get_page_hierarchy(), get_page_uri(), get_pages(), is_page(), page_uri_index(), wp_list_pages(), wp_page_menu()

See also index of Function Reference and index of Template Tags.