get_queried_object_id()
Gets the ID of the current query object. It can be: any post, category, tag, other taxonomy element, author's archive.
Works based on global $wp_query
.
Wrapper for WP_Query::get_queried_object_id().
Use get_queried_object() when you want to get all of the current query data, not just the query object ID.
Used By: is_page_template()
1 time — 0.000011 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.8, WP 4.6
No Hooks.
Return
Int
. ID of the queried object.
Post ID
― If we're on the post page.Term ID
― If the page of a taxonomy element (category, tag).Author ID
― If on the author's page.0
― If the query object does not provide an ID.
Usage
get_queried_object_id();
Examples
#1 Get the ID of the current request
$query_id = get_queried_object_id(); // 123
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
Since 3.1.0 | Introduced. |
get_queried_object_id() get queried object id code WP 6.3
function get_queried_object_id() { global $wp_query; return $wp_query->get_queried_object_id(); }