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

WordPress Trac noreply at wordpress.org
Thu Jun 9 07:05:06 UTC 2016


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

Comment (by jpdavoutian):

 Replying to [comment:16 boonebgorges]:
 > Replying to [comment:15 jpdavoutian]:
 > > @boonebgorges I have tested the solution and it works really great.
 > >
 > > My only concern is about bypassing `pre_posts_query` when reindexing
 content. I have worked out a solution for my case using the filter and a
 class variable. Maybe not the ideal solution but it was the only one that
 I could think of.
 > > I'm not sure how other plugins could make any use of this in case they
 need the original query.
 >
 > Thanks for the feedback. Can you say more about this concern? I'm not
 sure what you mean by "bypassing `pre_posts_query` when reindexing
 content".


 Well, there is this code from the solr-power plugin I mentioned earlier
 that does the indexing of posts:

 {{{
         $args  = array(
           'post_type'    => apply_filters( 'solr_post_types',
 get_post_types( array( 'exclude_from_search' => false ) ) ),
           'post_status'  => 'publish',
           'fields'     => 'ids',
           'posts_per_page' => absint( $limit ),
           'offset'     => absint( $prev )
         );
         $query   = new WP_Query( $args );
         $postids = $query->posts;
 }}}

 It gets all post ids of specific types in order to send these posts to
 solr server.
 If we have the `posts_pre_query` in place then we will get an empty result
 since nothing is initially indexed.

 My first attempt was to have an option in $args to force a database query
 instead of querying the solr server:

 {{{
         $args  = array(
           'external'     => FALSE,
 }}}

 Since there is no such option now, I raise a flag before calling the query
 and check for this flag in my `posts_pre_query` filter.
 An other solution could be to add the filter only after we have completed
 indexing.

 So, my concern is not how I can handle such a case within my plugin were I
 have set the filter and I can easily bypass it, but how a third party
 plugin could tell the system not to go through the `posts_pre_query`
 without being aware of my plugin.

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


More information about the wp-trac mailing list