Understanding the use of wp_reset_query();

I am not able to understand why we need to use wp_reset_query(); could anybody explain me?

global $more;
$more = 0;
query_posts('cat=3');
if(have_posts()) :
     while(have_posts()) :the_post();
     ?>
         <h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2>
         <div><?php the_content('Read More') ?></div>
     <?php
     endwhile;
endif;
wp_reset_query();?>

Related posts

Leave a Reply

1 comment

  1. When you call query_post it replaces the main query object with one of its own, but that isn’t desirable. If you want to return to the main query, you have to call wp_reset_query to do so whichr estores the original query.

    I’d advise strongly against the use of query_posts and instead suggest you use WP_Query. Query_posts is wasteful, slow, encourages bad practices, does not nest, and can get incredibly confusing.

    I recommend you read this:

    http://www.slideshare.net/andrewnacin/you-dont-know-query-wordcamp-netherlands-2012

    Its a presentation by a core developer, once you’ve read that you should know everything you will ever need to know, it contains all the important things that normally takes people years to learn, about how to do querys, what kinds and when to use them, and how to modify them