get_page_hierarchy()

You are here:

get_page_hierarchy( WP_Post[] $pagesint $page_id )

Order the pages with children under parents in a flat list.

Description Description

It uses auxiliary structure to hold parent-children relationships and runs in O(N) complexity


Top ↑

Parameters Parameters

$pages

(WP_Post[]) (Required) Posts array (passed by reference).

$page_id

(int) (Optional) Parent page ID. Default 0.


Top ↑

Return Return

(string[]) Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents.


Top ↑

Source Source

File: wp-includes/post.php

5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
function get_page_hierarchy( &$pages, $page_id = 0 ) {
    if ( empty( $pages ) ) {
        return array();
    }
 
    $children = array();
    foreach ( (array) $pages as $p ) {
        $parent_id                = intval( $p->post_parent );
        $children[ $parent_id ][] = $p;
    }
 
    $result = array();
    _page_traverse_name( $page_id, $children, $result );
 
    return $result;
}


Top ↑

Changelog Changelog

Changelog
VersionDescription
2.0.0Introduced.
Was this article helpful?
Dislike 0
Views: 2

Cart

Log in

Create an Account
Back to Top