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

WordPress Trac noreply at wordpress.org
Wed Jan 30 21:08:53 UTC 2013


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

Old description:

> The function `is_main_query()` is misleading, and rather useless. In
> practical situations, it is necessary to reference the method in the
> current query object, such as when used at the `pre_get_posts` action.
>
> The example in the Codex is even wrong:
>
>   add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
>
>   function foo_modify_query_exclude_category( $query ) {
>       if ( ! is_admin() && is_main_query() && ! $query->get( 'cat' ) )
>           $query->set( 'cat', '-5' );
>   }
>
> I propose deprecating the function as an encouragement for users to refer
> to the query object method instead.

New description:

 The function `is_main_query()` is misleading, and rather useless. In
 practical situations, it is necessary to reference the method in the
 current query object, such as when used at the `pre_get_posts` action.

 The example in the Codex is even wrong:
 {{{
   add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );

   function foo_modify_query_exclude_category( $query ) {
       if ( ! is_admin() && is_main_query() && ! $query->get( 'cat' ) )
           $query->set( 'cat', '-5' );
   }
 }}}
 I propose deprecating the function as an encouragement for users to refer
 to the query object method instead.

--

Comment (by SergeyBiryukov):

 Also suggested in [comment:ticket:13961:29].

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


More information about the wp-trac mailing list