WP_Posts_List_Table::_display_rows_hierarchical( array $pages, int $pagenum = 1, int $per_page = 20 )
- Source
wp-admin/includes/class-wp-posts-list-table.php:849
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pagesarray$pagenumintoptional- Default:
1 $per_pageintoptional- Default:
20
Performance profile
How much work a call to WP_Posts_List_Table::_display_rows_hierarchical() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 12–63
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_pages().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 133.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_pages()called directly - hookthird-party callbacks
apply_filters()one call below WP_Posts_List_Table::_display_rows_hierarchical() - cacheobject cache
wp_cache_delete()one call below WP_Posts_List_Table::_display_rows_hierarchical()
Further down the call graph this can also reach option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::_display_rows_hierarchical() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | get_pages() |
isset($value) | 38–53 | array_keys(), _prime_post_caches(), array_map(), update_post_author_caches() |
!isset($value) | 43–58 | array_keys(), _prime_post_caches(), array_map(), update_post_author_caches(), reset() |
isset($value) | 43–58 | get_pages(), array_keys(), _prime_post_caches(), array_map(), update_post_author_caches() |
!isset($value) | 48–63 | get_pages(), array_keys(), _prime_post_caches(), array_map(), update_post_author_caches(), reset() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 133 | 12–63 | 23 | |
| 8.5 | 133 | 12–63 | 23 | |
| 8.4 | 133 | 12–63 | 23 | |
| 8.3 | 133 | 12–63 | 23 | |
| 8.2 | 133 | 12–63 | 23 | |
| 8.1 | 133 | 12–63 | 23 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 135 | 12–65 | 23 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 6
- get_pages()Retrieves an array of pages (or hierarchical post type items).
- clean_post_cache()Will clean the post in the cache.
- _prime_post_caches()Adds any posts from the given IDs to the cache that do not already exist in cache.
- update_post_author_caches()Updates post author user caches for a list of post objects.
- WP_Posts_List_Table::_page_rows()Displays the nested hierarchy of sub-pages together with paging support, based on a top level page ID.
- WP_Posts_List_Table::single_row()
Used by · 1
- WP_Posts_List_Table::display_rows()Generates the list table rows.
Source code
private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { global $wpdb; $level = 0; if ( ! $pages ) { $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); if ( ! $pages ) { return; } } /* * Arrange pages into two parts: top level pages and children_pages. * children_pages is two dimensional array. Example: * children_pages[10][] contains all sub-pages whose parent is 10. * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations * If searching, ignore hierarchy and treat everything as top level */ if ( empty( $_REQUEST['s'] ) ) { $top_level_pages = array(); $children_pages = array(); foreach ( $pages as $page ) { // Catch and repair bad pages. if ( $page->post_parent === $page->ID ) { $page->post_parent = 0; $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) ); clean_post_cache( $page ); } if ( $page->post_parent > 0 ) { $children_pages[ $page->post_parent ][] = $page; } else { $top_level_pages[] = $page; } } $pages = &$top_level_pages; } $count = 0; $start = ( $pagenum - 1 ) * $per_page; $end = $start + $per_page; $to_display = array(); foreach ( $pages as $page ) { if ( $count >= $end ) { break; } if ( $count >= $start ) { $to_display[ $page->ID ] = $level; } ++$count; if ( isset( $children_pages ) ) { $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); } } // If it is the last pagenum and there are orphaned pages, display them with paging as well. if ( isset( $children_pages ) && $count < $end ) { foreach ( $children_pages as $orphans ) { foreach ( $orphans as $op ) { if ( $count >= $end ) { break; } if ( $count >= $start ) { $to_display[ $op->ID ] = 0; } ++$count; } } }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/class-wp-posts-list-table.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.