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
function get_queried_object() {
global $wp_query;
return $wp_query->get_queried_object();
}
Related
Uses | Description |
---|---|
WP_Query::get_queried_object()wp-includes/class-wp-query.php | Retrieves the currently queried object. |
Used by | Description |
---|---|
rest_get_queried_resource_route()wp-includes/rest-api.php | Gets the REST route for the currently queried object. |
WP_Widget_Custom_HTML::widget()wp-includes/widgets/class-wp-widget-custom-html.php | Outputs the content for the current Custom HTML widget instance. |
get_embed_template()wp-includes/template.php | Retrieves an embed template path in the current or parent template. |
wp_get_document_title()wp-includes/general-template.php | Returns document title for the current page. |
get_the_archive_title()wp-includes/general-template.php | Retrieves the archive title based on the queried object. |
term_description()wp-includes/category-template.php | Retrieves term description. |
wp_list_categories()wp-includes/category-template.php | Displays or retrieves the HTML list of categories. |
feed_links_extra()wp-includes/general-template.php | Displays the links to the extra feeds such as category feeds. |
single_post_title()wp-includes/general-template.php | Displays or retrieves page title for post. |
wp_title()wp-includes/general-template.php | Displays or retrieves page title for all areas of blog. |
single_term_title()wp-includes/general-template.php | Displays or retrieves page title for taxonomy term archive. |
WP::handle_404()wp-includes/class-wp.php | Set the Headers for 404, if nothing is found for requested URL. |
WP_Widget_Text::widget()wp-includes/widgets/class-wp-widget-text.php | Outputs the content for the current Text widget instance. |
edit_term_link()wp-includes/link-template.php | Displays or retrieves the edit term link with formatting. |
get_single_template()wp-includes/template.php | Retrieves path of single template in current or parent template. Applies to single Posts, single Attachments, and single custom post types. |
get_attachment_template()wp-includes/template.php | Retrieves path of attachment template in current or parent template. |
get_author_template()wp-includes/template.php | Retrieves path of author template in current or parent template. |
get_category_template()wp-includes/template.php | Retrieves path of category template in current or parent template. |
get_tag_template()wp-includes/template.php | Retrieves path of tag template in current or parent template. |
get_taxonomy_template()wp-includes/template.php | Retrieves path of custom taxonomy term template in current or parent template. |
get_page_template()wp-includes/template.php | Retrieves path of page template in current or parent template. |
wp_list_pages()wp-includes/post-template.php | Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format. |
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
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.