[wp-trac] [WordPress Trac] #23329: Deprecate is_main_query()

WordPress Trac noreply at wordpress.org
Wed Jan 30 22:44:52 UTC 2013


#23329: Deprecate is_main_query()
-------------------------+------------------
 Reporter:  ethitter     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.6
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------

Comment (by nacin):

 Originally, http://developer.wordpress.com/2012/05/14/querying-posts-
 without-query_posts/ used the function rather than the method. When I
 protested, JJJ came up with a fairly good explanation for why using the
 function actually made more sense in that situation. I disagreed, but it
 wasn't edited tat the time. It has since been changed.

 I kick myself for introducing the function. I really do. It had its
 purpose, to be a compliment to a WP_Query method the same way a function
 like `is_author()` is.

 It also ''does'' have a legitimate use. It means, simply: "Is $wp_query
 the main query?" This is false whenever query_posts() gets used. Given
 this function's purpose was to go up against query_posts(), it seemed like
 it could be useful. I didn't realize at the time how easily it'd be
 abused.

 It is worth noting that we could actually detect, inside is_main_query(),
 if pre_get_posts is the current hook. We could even go so far — not
 easily, but it is possible — to forcibly call the method on the query
 object when the function is summoned inside pre_get_posts. That's going
 overboard, but still, it's possible.

 I don't entirely see what benefit deprecating this function will have.
 Maybe just a `_doing_it_wrong()` when used inside pre_get_posts.

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


More information about the wp-trac mailing list