* The query API attempts to get which part of WordPress the user is on. It
* also provides functionality for getting URL query information.
* @link https://developer.wordpress.org/themes/basics/the-loop/ More information on The Loop.
* Retrieves the value of a query variable in the WP_Query class.
* @since 3.9.0 The `$default` argument was introduced.
* @global WP_Query $wp_query WordPress Query object.
* @param string $var The variable key to retrieve.
* @param mixed $default Optional. Value to return if the query variable is not set. Default empty.
* @return mixed Contents of the query variable.
function get_query_var( $var, $default = '' ) {
return $wp_query->get( $var, $default );
* Retrieves the currently queried object.
* Wrapper for WP_Query::get_queried_object().
* @global WP_Query $wp_query WordPress Query object.
* @return WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object.
function get_queried_object() {
return $wp_query->get_queried_object();
* Retrieves the ID of the currently queried object.
* Wrapper for WP_Query::get_queried_object_id().
* @global WP_Query $wp_query WordPress Query object.
* @return int ID of the queried object.
function get_queried_object_id() {
return $wp_query->get_queried_object_id();
* Sets the value of a query variable in the WP_Query class.
* @global WP_Query $wp_query WordPress Query object.
* @param string $var Query variable key.
* @param mixed $value Query variable value.
function set_query_var( $var, $value ) {
$wp_query->set( $var, $value );
* Sets up The Loop with query parameters.
* Note: This function will completely override the main query and isn't intended for use
* by plugins or themes. Its overly-simplistic approach to modifying the main query can be
* problematic and should be avoided wherever possible. In most cases, there are better,
* more performant options for modifying the main query such as via the {@see 'pre_get_posts'}
* action within WP_Query.
* This must not be used within the WordPress Loop.
* @global WP_Query $wp_query WordPress Query object.
* @param array|string $query Array or string of WP_Query arguments.
* @return WP_Post[]|int[] Array of post objects or post IDs.
function query_posts( $query ) {
$GLOBALS['wp_query'] = new WP_Query();
return $GLOBALS['wp_query']->query( $query );
* Destroys the previous query and sets up a new query.
* This should be used after query_posts() and before another query_posts().
* This will remove obscure bugs that occur when the previous WP_Query object
* is not destroyed properly before another is set up.
* @global WP_Query $wp_query WordPress Query object.
* @global WP_Query $wp_the_query Copy of the global WP_Query instance created during wp_reset_query().
function wp_reset_query() {
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
* After looping through a separate query, this function restores
* the $post global to the current post in the main query.
* @global WP_Query $wp_query WordPress Query object.
function wp_reset_postdata() {
if ( isset( $wp_query ) ) {
$wp_query->reset_postdata();
* Determines whether the query is for an existing archive page.
* Archive pages include category, tag, author, date, custom post type,
* and custom taxonomy based archives.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @see is_post_type_archive()
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for an existing archive page.
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_archive();
* Determines whether the query is for an existing post type archive page.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param string|string[] $post_types Optional. Post type or array of posts types
* to check against. Default empty.
* @return bool Whether the query is for an existing post type archive page.
function is_post_type_archive( $post_types = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_post_type_archive( $post_types );
* Determines whether the query is for an existing attachment page.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param int|string|int[]|string[] $attachment Optional. Attachment ID, title, slug, or array of such
* to check against. Default empty.
* @return bool Whether the query is for an existing attachment page.
function is_attachment( $attachment = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_attachment( $attachment );
* Determines whether the query is for an existing author archive page.
* If the $author parameter is specified, this function will additionally
* check if the query is for one of the authors specified.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param int|string|int[]|string[] $author Optional. User ID, nickname, nicename, or array of such
* to check against. Default empty.
* @return bool Whether the query is for an existing author archive page.
function is_author( $author = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_author( $author );
* Determines whether the query is for an existing category archive page.
* If the $category parameter is specified, this function will additionally
* check if the query is for one of the categories specified.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param int|string|int[]|string[] $category Optional. Category ID, name, slug, or array of such
* to check against. Default empty.
* @return bool Whether the query is for an existing category archive page.
function is_category( $category = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_category( $category );
* Determines whether the query is for an existing tag archive page.
* If the $tag parameter is specified, this function will additionally
* check if the query is for one of the tags specified.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param int|string|int[]|string[] $tag Optional. Tag ID, name, slug, or array of such
* to check against. Default empty.
* @return bool Whether the query is for an existing tag archive page.
function is_tag( $tag = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_tag( $tag );
* Determines whether the query is for an existing custom taxonomy archive page.
* If the $taxonomy parameter is specified, this function will additionally
* check if the query is for that specific $taxonomy.
* If the $term parameter is specified in addition to the $taxonomy parameter,
* this function will additionally check if the query is for one of the terms
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param string|string[] $taxonomy Optional. Taxonomy slug or slugs to check against.
* @param int|string|int[]|string[] $term Optional. Term ID, name, slug, or array of such
* to check against. Default empty.
* @return bool Whether the query is for an existing custom taxonomy archive page.
* True for custom taxonomy archive pages, false for built-in taxonomies
* (category and tag archives).
function is_tax( $taxonomy = '', $term = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_tax( $taxonomy, $term );
* Determines whether the query is for an existing date archive.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for an existing date archive.
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_date();
* Determines whether the query is for an existing day archive.
* A conditional check to test whether the page is a date-based archive page displaying posts for the current day.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for an existing day archive.
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_day();
* Determines whether the query is for a feed.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @param string|string[] $feeds Optional. Feed type or array of feed types
* to check against. Default empty.
* @return bool Whether the query is for a feed.
function is_feed( $feeds = '' ) {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_feed( $feeds );
* Is the query for a comments feed?
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for a comments feed.
function is_comment_feed() {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_comment_feed();
* Determines whether the query is for the front page of the site.
* This is for what is displayed at your site's main URL.
* Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'.
* If you set a static page for the front page of your site, this function will return
* true when viewing that page.
* Otherwise the same as @see is_home()
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for the front page of the site.
function is_front_page() {
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return $wp_query->is_front_page();
* Determines whether the query is for the blog homepage.
* The blog homepage is the page that shows the time-based blog content of the site.
* is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front'
* If a static page is set for the front page of the site, this function will return true only
* on the page you set as the "Posts page".
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global WP_Query $wp_query WordPress Query object.
* @return bool Whether the query is for the blog homepage.