Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

WHen should i reset WP_Query?

When should i reset <?php wp_reset_query(); ?> ?

I was stuck for 24hours, untill i came across that i need to <?php wp_reset_query(); ?>.

SO i was wondering, when do i need to use it? every single time?

2 Answers

According to the docs, it says This function should be called after query_posts(), if you must use that function. So I'm guessing your code used query_posts()

So basicall after query_posts() ? if i don't have it, i don't need to call it?

DO NOT USE QUERY POSTS EVER. It is terrible practice.

http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts

use WP_Query instead

and always end with

wp_reset_postdata();