WordPress at Your Fingertips

wp_reset_query() WP 2.3.0

Invalidates (destroys) the data of the last query created for use in an arbitrary WordPress Loop and restores the default loop data.

An arbitrary query (WordPress Loop) is performed by query_posts() function, which overwrites the global variable $wp_query.

This should be used after query_posts() or if $posts or $wp_query variables have been used in the code. This will remove obscure bugs that occur when default WP_Query object was overwritten.

The function should be called immediately after an arbitrary loop and needs to all conditional tags work correctly and global variables correspond to the current page (query).

1 time — 0.000022 sec (very fast) | 50000 times — 0.04 sec (speed of light)

No Hooks.


null. Nothing.




#1 Query data reset

This example shows how to use the function after an arbitrary Loop:


if( have_posts() ) : while( have_posts() ) : the_post();
	<a href="<?php the_permalink() ?>"><?php the_title() ?></a><br />
endwhile; endif;



  • 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().


Since 2.3.0 Introduced.

Code of wp_reset_query() WP 5.7.2

function wp_reset_query() {
	$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];

From tag: reset

More from tag: query

More from category: Queries

vladlu 100vlad.lu
Editors: Kama 100
No comments
    Log In