Uses
| Uses | Description |
|---|---|
| wp-includes/query.php: wp_reset_postdata() | After looping through a separate query, this function restores the $post global to the current post in the main 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.
query_posts() will change your main query and is not recommended. Only use if absolutely necessary. Creating a new instance of WP_Query or get_posts() is preferred for secondary loops. If you would like to modify the main query, use the pre_get_posts action.
File: wp-includes/query.php
function wp_reset_query() {
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
wp_reset_postdata();
} | Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_reset_query