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

WordPress Trac noreply at wordpress.org
Fri Apr 29 22:23:15 UTC 2016


#36687: Feature to override WP_Query to provide results from other source
-----------------------------+------------------------------
 Reporter:  jpdavoutian      |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Query            |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------
Changes (by jpdavoutian):

 * keywords:  reporter-feedback =>


Comment:

 Thanks for the quick reply.

 Yes, I have seen the plugins you suggest.
 There are a couple of issues with them.

 First of all they deal only with search results and not the wordpress
 queries in general.

 Secondly, you can see that the posts_request filter actually is returning
 an sql statement that is dummy.
 https://github.com/10up/ElasticPress/blob/develop/classes/class-ep-wp-
 query-integration.php#L336
 Although this approach is clever, it actually hits the database for
 nothing.

 But the most serious issue in my opinion is that it does not allow to
 intercept queries when we request only post ids. You simply cannot do it.
 Many plugins make use of such queries and there is no way these queries to
 be served from solr or any other similar service.

 By having one more filter in wp-includes/query.php and a few more checks
 in code, we could actually generalize the use of search services without
 affecting or rewriting other plugins.
 I have placed an action in wp-includes/query.php, line 3548
 $this->is_external_query = apply_filters_ref_array(
 'posts_query_external', array( $this->request, &$this ) );
 and later on I just check the $this->is_external_query to if I need to
 count posts or other stuff.

 I'm already working on such a case (woocommerce layered navigation) and
 have great success till now and the performance improvement is huge.
 There are of course some minor issues I haven't solved yet and maybe cases
 I can't even think of, since my experience in wordpress is limited (that's
 why I haven't uploaded any code yet).

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


More information about the wp-trac mailing list