[wp-hackers] Including javascript in the footer

Otto otto at ottodestruct.com
Tue May 17 17:28:36 UTC 2011


On Tue, May 17, 2011 at 12:19 PM, Dylan Kuhn <dylan.k.kuhn at gmail.com> wrote:
> So would multiple Loops mean multiple trips through the main query results,
> or multiple queries with different results? If it's the latter, I'd like to
> know where I can learn more.

Either. Both. Depends on what you're doing.

Once you've defined a query, you can loop through it as many times as
you want. Creating the query makes it go pull all the relevant results
from the DB, store them in an array (more or less), then you just go
through them one by one.

The main query is really not special, other than it's a) the main one
and b) automatically run at page load. Redefining it using query_posts
or something does mean that more SQL has to occur to get the new
results, but looping through it again doesn't make it go back to the
database.

> I still use instances of WP_Query frequently in my templates to loop through
> content related in different ways to the main query. Is that wrong? How
> would you look ahead at that content?

Define your query, loop through it. When you need to loop through it
again, don't re-define it, just rewind it and loop through it again.

$myquery = new WP_Query(...);
... loop ...
$myquery->rewind_posts();
--- start again with a new loop through it ...


More information about the wp-hackers mailing list