[wp-hackers] wp_reset_query() (was Complete list of articles)
Jeremy Clarke
jer-wphackers at simianuprising.com
Thu Feb 7 16:21:25 GMT 2008
> I've mentioned it on the forums before, but generally speaking I
> prefer to discourage the use of query_posts() except to modify the
> main loop for special cases. It's really better to create a new
> WP_Query object and use that (for those "extra" loops you might happen
> to need). That way the main loop for the page stays unmolested.
I agree with this completely. in the codex query_posts() is presented
as the default/best way to solve the problem of multiple loops (and
for pretty good reason, it's very easy to use in conjuction with just
copy/pasting the other loop code).
But using query_posts() leads to a ton of weird behavior that I don't
think people expect at all, like, for example, when your category
pages no longer return true for is_category() because you used
query_posts() to get the 5 most recent posts site-wide for a widget or
something. The 'new WP_Query()' way is almost always what people want
because it leaves the original query variables alone.
It would be really nice to have a convenient wrapper function similar
to query_posts() but that has the behaviors of new WP_Query(). At this
point using the latter is relatively complicated and probably requires
actual php knowledge, rather than the simplified PHP knowledge that is
required for most other theme-related activities (i.e. using functions
and arguments but not much else). something like new_query()?
Jeremy Clarke
http://simianuprising.com
More information about the wp-hackers
mailing list