[wp-trac] [WordPress Trac] #19631: Consider a doing_it_wrong call for query_posts()

WordPress Trac wp-trac at lists.automattic.com
Wed Dec 21 11:58:14 UTC 2011


#19631: Consider a doing_it_wrong call for query_posts()
-------------------------+-----------------------------
 Reporter:  johnbillion  |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:
 Severity:  minor        |   Keywords:
-------------------------+-----------------------------
 The `query_posts()` function affects the main query, so things (like
 template conditionals) can break if plugins or themes use it without
 calling `wp_reset_query()` immediately afterwards.

 Unless there is a situation I haven't considered, `query_posts()`
 shouldn't be used at all on requests where the main query is run
 (`query_posts()` of course has a use in situations like AJAX calls when
 the main query isn't run).

  * For secondary loops, `get_posts()` or the `WP_Query()` class should be
 used.
  * To modify the main query, there are hooks all over the place, such as
 'request', 'parse_request', 'parse_query', and 'pre_get_posts', in
 addition to the SQL filters such as 'posts_where', 'posts_join', etc.

 Maybe `doing_it_wrong()` should be called if `query_posts()` is used after
 the main query is run, with pointers toward a relevant Codex article on
 secondary loops or filtering the main loop.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19631>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list