When to use Reset Query
-
I am excluding posts in a particular category from pages that use the index.php as a template using
query_posts()
. It’s the only way I have found to exclude posts from a category that isn’t a plug-in and doesn’t mess up something else on my site.
Here’s the code I have:<?php query_posts($query_string . '&cat=-3'); ?> <?php if (have_posts()) : ?>
My question is whether it is necessary to reset query after the loop, which would look like this:
<?php endif; ?> <?php wp_reset_query(); ?>
Is there a benefit or drawback to this? On a basic level I understand what the reset is doing, but as far as best practices – should the query be reset every time I use
query_posts()
(since I’m changing the state of the query)or is there a rule of when to use and when not to use?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘When to use Reset Query’ is closed to new replies.