[wp-trac] [WordPress Trac] #36687: Feature to override WP_Query to provide results from other source

WordPress Trac noreply at wordpress.org
Tue Jun 14 01:59:27 UTC 2016


#36687: Feature to override WP_Query to provide results from other source
-----------------------------------+--------------------------
 Reporter:  jpdavoutian            |       Owner:  jpdavoutian
     Type:  feature request        |      Status:  closed
 Priority:  normal                 |   Milestone:  4.6
Component:  Query                  |     Version:
 Severity:  normal                 |  Resolution:  fixed
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+--------------------------
Changes (by boonebgorges):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"37692"]:
 {{{
 #!CommitTicketReference repository="" revision="37692"
 Query: Allow plugins to supply post results instead of having `WP_Query`
 fetch them from the database.

 Returning a non-null value from the new `posts_pre_query` filter will
 cause
 `WP_Query` to skip its database query, so that posts data can be provided
 from
 elsewhere. This is useful in cases where post data may be mirrored in a
 separate location, such as an external search application.

 Developers should note that the `WP_Query` properties generally used to
 calculate pagination - specifically, `found_posts` and `max_num_pages`,
 which
 are determined by default in `set_found_posts()` - must be provided
 explicitly
 when using the `posts_pre_query` filter; since `WP_Query` will not be
 contacting the database, it will have no access to `SELECT FOUND_ROWS()`.
 The `WP_Query` instance is passed to `posts_pre_query` by reference, so
 that
 these properties can be set manually if needed.

 Props jpdavoutian, tlovett1.
 Fixes #36687.
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36687#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list