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

WordPress Trac noreply at wordpress.org
Mon Sep 16 04:23:27 UTC 2013


#19631: Consider a doing_it_wrong call for query_posts()
-------------------------+-----------------------------
 Reporter:  johnbillion  |       Owner:
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:  Future Release
Component:  Query        |     Version:
 Severity:  minor        |  Resolution:
 Keywords:  close        |
-------------------------+-----------------------------

Comment (by rmccue):

 Replying to [comment:8 nacin]:
 > Because it is really easy to use and the alternatives are tougher to
 articulate and code, especially to people just hacking together a theme.
 >
 > Re-opening for consideration down the line. I've been thinking about a
 new `pre_main_query` hook that parallels pre_get_posts but only runs
 `$query->is_main_query() and ! $query->is_admin()`. That might take some
 of the magic out of using pre_get_posts.

 Along those lines, maybe we could have something like:

 {{{
 function wp_modify_query($args) {
     add_filter('pre_get_posts', function ($query) use ($args) {
         return array_merge($query, $args);
     });
 }
 }}}

 (Obviously with 5.2 syntax, this is just for demonstration)

 This would work similarly to how we do admin menu items by hiding the fact
 that we have a filter at all, which might be a bit easier for themers to
 use than the hook, and they can use this directly in their
 `functions.php`. (And maybe a corollary function as
 `wp_modify_main_query`.) Just a thought if we do want to push away from
 `query_posts()` but still keep it simple for themers.

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


More information about the wp-trac mailing list