Article written by Ronnie T. Dodger

11 responses to “Undocumented WordPress Query Function: wp_reset_query()”

  1. Danny Foo

    Thanks a lot! This definitely solved my problem as I use a lot of query_posts in my custom themes. And I’m no PHP-developer.

    Plus, you’re damn right about the WordPress support. I couldn’t get any answers from the Codex nor the forums.

    Thanks again for this. :)

  2. tades

    great, I’ll use it on my theme

  3. paul

    Great insight. I have been having some similar issues, but have found that even when I use the new WP_Query() call instead of query_posts(), my loops are still not resetting.

    I execute a couple of embedded WP_Query() calls in a nav.php custom menu, attempting to retrieve a nested category, sub-category and post title multi-tiered menu. It works absolutely perfectly, displays correctly and links to where it should, except that the last post to be included in that menu carries its id over to the single.php page when it is called, meaning that no matter what post is selected, the same post keeps appearing. (the URL is correct for each individual post, it is just the post title and content that is stuck.

    If you could shed any light on this nightmare for me I would greatly appreciate it :) I have searched for hours and have tried many “hit and miss” fixes, but no matter what I try the loops don’t seem to be resetting once they are done.

  4. Matt Brewster

    Great tip, thanks :)

  5. Israel Cefrin

    Greetings
    Tks a lot for this post. I was struggling with my sidebar.php to hide admin form when not in home about a couple of weeks.

    Best regards

  6. Ryan

    Thank you…so much. Was always having trouble with a custom query in a lefthand sidebar. Without the reset_query function, the right-hand content would always be the last page or post retrieved in the sidebar’s custom query. A great tip.

  7. Chris Webb

    So useful, thanks for sharing this..

  8. Tsalagi

    There is now a reference to this function in the codex. Search wp_reset_query.
    There is also an ongoing discussion on the forums. Search for “query_posts codex correct or not?” in the forums. Thanks for posting about this issue. The more the word gets out the more stability folks will have with their blogs and themes.

  9. cloud blogger

    This seems really usefull. Thanks for bringing this up. I always wonder why something so widely used as WordPress still has such an awful documentation and especially API. Sometimes there are too many ways and not all work…

  10. kamal

    First Thanks to Google “I’m feeling Lucky” button who drive me directly to this paradise of help :p
    So, thank you for the help, you solve a lot of my time,
    Thanks again.

Leave a Reply

Note: Real or legitimate company names only! Names such as SEO Illinois, Web Design Aurora, and other promotional keyword text in the name field will be automatically deleted. No exceptions. Nicknames are okay, as long as they do not violate the keyword rule.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>