Resetting the Query

Once you've modified a Loop query, it stays modified! Therefore, before you start a new Loop, you need to reset the query. Otherwise, your new modifications will operate on the posts already returned by your first query—and that leads to some very unpredictable results. Fortunately, resetting the query takes just one line of code, as shown in Listing 7-8.

Listing 7-8. Resetting the query

That's it! Remember to reset the query in between each of your Loops to avoid strange errors in your advanced layouts.

Earlier, I showed you how to preserve the original query while adding your modifications. If you want to save the original query for use after your new queries, save it to a variable (like $original_query), then reassign it when you're done, as shown in Listing 7-9.

Listing 7-9. Preserving the original query

0 0

Post a comment