[wp-hackers] Including javascript in the footer
Dylan Kuhn
dylan.k.kuhn at gmail.com
Tue May 17 17:44:27 UTC 2011
On Tue, May 17, 2011 at 10:28 AM, Otto <otto at ottodestruct.com> wrote:
>
> 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.
>
Ah - I get how query_posts creates multiple main queries, what threw me for
a loop in this thread is that I've always seen it done in template code
(where I understand WP_Query is preferred). How would it be done before
wp_enqueue_scripts fires?
> 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();
>
So likewise - I always do that in templates. Is the right way to instantiate
the query prior to wp_enqueue_scripts, so the results can be analyzed for
script dependencies?
Thanks as always for the answers.
-dylan-
More information about the wp-hackers
mailing list