get_queried_object(): WP_Term|WP_Post_Type|WP_Post|WP_User|null
Retrieves the currently queried object.
Description
Wrapper for WP_Query::get_queried_object().
Return
WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object.
Source
File: wp-includes/query.php
.
View all references
function get_queried_object() {
global $wp_query;
return $wp_query->get_queried_object();
}
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
The “currently-queried object” means the object that is the subject of the webpage:
– On a category archive, tag archive, or other taxonomy archive page, it will return the
WP_Term
object of the current category, tag, or other term.– If you have set a posts page where your basic posts are displayed,
get_queried_object()
will return theWP_Post
object of that page.– On post type archive pages, it will return the
WP_Post_Type
object of the given post type.– On an author archive page, it will return the
WP_User
object of that author.– On any singular page (a single post, a single page, or a post in a custom post type), it will return the
WP_Post
object of that post or page.Be careful not to use
get_queried_object()
andget_post()
orglobal $post
interchangeably. On a singular post, those will all return the same thing. But, for example, if you have a page called “Blog” that displays your posts,get_queried_object()
will return the “Blog” page whereasget_post()
will return the current post in the loop.