Automated Indexes and wp_reset_query()

I’ve made a code change to the WordPress indexing system outlined in my previous post. If you had problems with the template, try the new code.

What I’ve done is add the wp_reset_query() function to the end of the loop that gathers the pages. This can avoid conflicts with other code that may be running in your templates.

In general, it’s good advice to any of you WordPress coders out there who use the query_posts() function, or in general run custom instances of the $wp_query object in plugins or templates. When you’re done with whatever you’re doing, put things back the way you found them by following it up with a call to wp_reset_query().

(By the way — it isn’t terribly well documented yet, but the original discussion leading to the function’s creation can be found at

This entry was posted in Webcraft and tagged , , , , . Bookmark the permalink.

1 Response to Automated Indexes and wp_reset_query()

  1. The codex suggests creating a new WP_Query object and not disturbing the query_posts() in the main loop.

    I ran into the same problem you did a few weeks ago, and it was a PITA to figure it all out. Hard to Google for and I wished I stumbled across your post in the beginning.

Leave a Reply

Your email address will not be published.