Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#18677 closed enhancement (fixed)

is_main_query()

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

Description

Often times, it's very beneficial to check whether you're working with the main query. Examples might include operations on the pre_get_posts action.

Developers with knowledge of the internals know to compare the query object against $wp_the_query, but that is rather cryptic and pretty hidden. Most documentation I can find on the usage of query_posts(), WP_Query, and get_posts() fail to mention $wp_the_query anywhere. Though, they do often mention wp_reset_query(), which restores $wp_query from $wp_the_query.

It'd be nice to expose a new function and new WP_Query method to leverage this. Attached patch introduces is_main_query() and the corresponding method.

Attachments (1)

18677.diff (733 bytes) - added by nacin 13 years ago.

Download all attachments as: .zip

Change History (4)

@nacin
13 years ago

#1 @scribu
13 years ago

+1 from me.

#2 @westi
13 years ago

+∞

#3 @nacin
13 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [18699]:

is_main_query(). fixes #18677.

Note: See TracTickets for help on using tickets.