get_queried_object()

Retrieve the currently-queried object.


Description Description

Wrapper for WP_Query::get_queried_object().


Top ↑

Return Return

(object) Queried object.



Top ↑

Source Source

File: wp-includes/query.php

function get_queried_object() {
	global $wp_query;
	return $wp_query->get_queried_object();
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Michael Dance

    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 the WP_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() and get_post() or global $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 whereas get_post() will return the current post in the loop.

You must log in before being able to contribute a note or feedback.