Make WordPress Core

Opened 10 years ago

Last modified 9 years ago

#23329 closed enhancement

Deprecate is_main_query() — at Version 1

Reported by: ethitter's profile ethitter Owned by:
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.3
Component: Query Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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.

Change History (2)

#1 @SergeyBiryukov
10 years ago

  • Description modified (diff)

Also suggested in ticket:13961:29.

@ethitter
10 years ago

Note: See TracTickets for help on using tickets.