get_queried_object(): WP_Term|WP_Post_Type|WP_Post|WP_User|null
- Since
- 3.1.0
- Source
wp-includes/query.php:43
Description
Wrapper for WP_Query::get_queried_object().
Compatibility
- WordPress
- since 3.1.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.
Return value
WP_Term|WP_Post_Type|WP_Post|WP_User|null- The queried object.
Performance profile
How much work a call to get_queried_object() 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
- Trivial
- Scaling
- Constant
- Instructions
- 4
- Plugin surface
- None
- Called by
- 31
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 4.
Nothing here hands control to plugin code.
31 places in core call this, so the cost is paid more often than your own code shows.
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 get_queried_object() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | ->get_queried_object() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 4 instructions, 4 executed per call, 0 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.
Used by · 31
- WP::handle_404()Set the Headers for 404, if nothing is found for requested URL.
- WP_Widget_Custom_HTML::widget()Outputs the content for the current Custom HTML widget instance.
- WP_Widget_Text::widget()Outputs the content for the current Text widget instance.
- block_core_breadcrumbs_get_archive_breadcrumbs()Generates breadcrumb items for archive pages.
- edit_term_link()Displays or retrieves the edit term link with formatting.
- feed_links_extra()Displays the links to the extra feeds such as category feeds.
- get_attachment_template()Retrieves path of attachment template in current or parent template.
- get_author_template()Retrieves path of author template in current or parent template.
- get_category_template()Retrieves path of category template in current or parent template.
- get_embed_template()Retrieves an embed template path in the current or parent template.
- get_page_template()Retrieves path of page template in current or parent template.
- get_single_template()Retrieves path of single template in current or parent template. Applies to single Posts, single Attachments, and single custom post types.
Show all 31
- get_tag_template()Retrieves path of tag template in current or parent template.
- get_taxonomy_template()Retrieves path of custom taxonomy term template in current or parent template.
- get_the_archive_title()Retrieves the archive title based on the queried object.
- render_block_core_navigation_link()Renders the `core/navigation-link` block.
- render_block_core_navigation_submenu()Renders the `core/navigation-submenu` block.
- render_block_core_term_count()Renders the `core/term-count` block on the server.
- render_block_core_term_name()Renders the `core/term-name` block on the server.
- render_block_core_term_template()Renders the `core/term-template` block on the server.
- rest_get_queried_resource_route()Gets the REST route for the currently queried object.
- single_post_title()Displays or retrieves page title for post.
- single_term_title()Displays or retrieves page title for taxonomy term archive.
- term_description()Retrieves term description.
- twentyfifteen_author_bio_template()Prevents `author-bio.php` partial template from interfering with rendering an author archive of a user with the `bio` username.
- twentynineteen_get_the_archive_title()Filters the default archive titles.
- twentythirteen_author_bio_template()Prevents `author-bio.php` partial template from interfering with rendering an author archive of a user with the `bio` username.
- wp_get_document_title()Returns document title for the current page.
- wp_list_categories()Displays or retrieves the HTML list of categories.
- wp_list_pages()Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format.
- wp_title()Displays or retrieves page title for all areas of blog.
Source code
function get_queried_object() { global $wp_query; return $wp_query->get_queried_object();}Changelog
Introduced in 3.1.0. 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-includes/query.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.