Contents
What is wp_ reset_ postdata?
wp_reset_postdata() restores the global $post variable to the current post in the main query (contained in the global $wp_query variable as opposed to the $sec_query variable), so that the template tags refer to the main query loop by default again.
What is the use of wp_ reset_ query?
wp_reset_query() Destroys the previous query and sets up a new query.
How do I reset a WordPress query?
Quick summary for future reference:
- wp_reset_postdata() -> best used after custom or multiple loops created with WP_Query.
- wp_reset_query() -> best used after a query_posts loop to reset a custom query.
- rewind_posts() -> best for re-using the same query on the same page.
How do I use WPquery in WordPress?
How to Use WP_Query
- Get Started with a Custom Loop. One of the best ways to get to know the WP_Query call is through the WordPress Loop.
- Arguments: The Backbone of Custom Queries in WordPress.
- Parameters in WP_Query: Category, Tag, and More.
- Modify Objects with Methods and Properties.
What does WP _ reset _ Postdata ( ) do?
wp_reset_postdata() After looping through a separate query, this function restores the $post global to the current post in the main query.
When to use WP _ reset _ query ( ) after a custom loop?
In the WP Codex it states that you should use wp_reset_query () after a custom loop (first example) http://codex.wordpress.org/Function_Reference/wp_reset_query Is the codex wrong then? wp_reset_postdata () – ensures that the global $post has been restored to the current post in the main query.
When to use WP reset query in WordPress?
In example2 there’s a comment: And really you should never use wp_reset_query because you shouldn’t use query_posts!? In the WP Codex it states that you should use wp_reset_query () after a custom loop (first example) http://codex.wordpress.org/Function_Reference/wp_reset_query
How to reset the global post variable in WordPress?
The global $post variable is used by template tags by default. wp_reset_postdata () restores the global $post variable to the current post in the main query (contained in the global $wp_query variable as opposed to the $sec_query variable), so that the template tags refer to the main query loop by default again.