функция
since 1.5.1
get_page_children()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_page_children( int $page_id, WP_Post[] $pages ): WP_Post[]
Описание
Потомки определяются по массиву $pages, переданному в функцию. Запросы к базе данных не выполняются.
Оригинал (английский)
Descendants are identified from the $pages array passed to the function. No database queries are performed.
Параметры
$page_id
int
обязательный
ID страницы.
$pages
WP_Post[]
обязательный
Список объектов страниц, среди которых нужно определить потомков.
Возвращаемое значение
WP_Post[]
Исходный код
wp-includes/post.php:6248
function get_page_children( $page_id, $pages ) {
// Build a hash of ID -> children.
$children = array();
foreach ( (array) $pages as $page ) {
$children[ (int) $page->post_parent ][] = $page;
}
$page_list = array();
// Start the search by looking at immediate children.
if ( isset( $children[ $page_id ] ) ) {
// Always start at the end of the stack in order to preserve original `$pages` order.
$to_look = array_reverse( $children[ $page_id ] );
while ( $to_look ) {
$p = array_pop( $to_look );
$page_list[] = $p;
if ( isset( $children[ $p->ID ] ) ) {
foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
// Append to the `$to_look` stack to descend the tree.
$to_look[] = $child;
}
}
}
}
return $page_list;
}
История изменений
| Версия | Описание |
|---|---|
| 1.5.1 | Introduced. |

