parent_dropdown( int $default_page = 0, int $parent_page = 0, int $level = 0, int|WP_Post $post = null ): void|false
- Since
- 1.5.0, 4.4.0
- Source
wp-admin/includes/template.php:936
Compatibility
- WordPress
- since 4.4.0
- 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
$default_pageintoptional- The default page ID to be pre-selected. Default 0.Default:
0 $parent_pageintoptional- The parent page ID. Default 0.Default:
0 $levelintoptional- Page depth level. Default 0.Default:
0 $postint|WP_Postoptional- Post ID or WP_Post object.Default:
null
Return value
void|false- Void on success, false if the page has no children.
Performance profile
How much work a call to parent_dropdown() 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
- 23–26
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->get_results().
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 76.
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_post()called directly - sqldatabase query
->get_results()called directly - hookthird-party callbacks
apply_filters()one call below parent_dropdown()
Further down the call graph this can also reach option, cache, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost parent_dropdown() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 23–26 | get_post(), ->prepare(), ->get_results() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 76 instructions, 23–26 executed per call, 6 branches. The work does not change between versions.
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 · 4
- get_post()Retrieves post data given a post ID or post object.
- selected()Outputs the HTML selected attribute.
- esc_html()Escaping for HTML blocks.
- parent_dropdown()Prints out option HTML elements for the page parents drop-down.
Used by · 1
- parent_dropdown()Prints out option HTML elements for the page parents drop-down.
Source code
function parent_dropdown( $default_page = 0, $parent_page = 0, $level = 0, $post = null ) { global $wpdb; $post = get_post( $post ); $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent_page ) ); if ( $items ) { foreach ( $items as $item ) { // A page cannot be its own parent. if ( $post && $post->ID && (int) $item->ID === $post->ID ) { continue; } $pad = str_repeat( ' ', $level * 3 ); $selected = selected( $default_page, $item->ID, false ); echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html( $item->post_title ) . '</option>'; parent_dropdown( $default_page, $item->ID, $level + 1 ); } } else { return false; }}Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$post argument was added.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/template.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.