get_queried_object_id(): int
- Since
- 3.1.0
- Source
wp-includes/query.php:59
Description
Wrapper for WP_Query::get_queried_object_id().
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
int- ID of the queried object.
Performance profile
How much work a call to get_queried_object_id() 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
- 21
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.
21 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_id() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | ->get_queried_object_id() |
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 · 21
- WP::register_globals()Set up the WordPress Globals.
- WP_Query::generate_postdata()Generates post data.
- WP_Widget_Recent_Posts::widget()Outputs the content for the current Recent Posts widget instance.
- block_core_home_link_build_li_wrapper_attributes()Builds an array with classes and style for the li wrapper
- get_custom_logo()Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
- get_page_template()Retrieves path of page template in current or parent template.
- is_page_template()Determines whether the current post uses a page template.
- redirect_canonical()Redirects incoming links to the proper URL based on the site url.
- rel_canonical()Outputs rel=canonical for singular queries.
- render_block_core_home_link()Renders the `core/home-link` block.
- render_block_core_navigation_link()Renders the `core/navigation-link` block.
- render_block_core_navigation_submenu()Renders the `core/navigation-submenu` block.
Show all 21
- render_block_core_page_list()Renders the `core/page-list` block on server.
- render_block_core_site_title()Renders the `core/site-title` block on the server.
- rest_get_queried_resource_route()Gets the REST route for the currently queried object.
- twentyseventeen_should_show_featured_image()Shows the featured image below the header on single posts and pages, unless the page is the front page.
- twentytwenty_site_logo()Displays the site logo, either text or image.
- wp_get_canonical_url()Returns the canonical URL for a post.
- wp_get_shortlink()Returns a shortlink for a post, page, attachment, or site.
- 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.
Source code
function get_queried_object_id() { global $wp_query; return $wp_query->get_queried_object_id();}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.