[wp-trac] [WordPress Trac] #41700: New filter return in WP_Query

WordPress Trac noreply at wordpress.org
Thu Aug 31 16:16:55 UTC 2017


#41700: New filter return in WP_Query
--------------------------+------------------------------
 Reporter:  spacedmonkey  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  1.5
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  performance
--------------------------+------------------------------

Comment (by spacedmonkey):

 I have a plugin that caches the result of WP_Query called
 [https://github.com/TimeIncOSS/enhanced-post-cache enhanced post cache].
 It hooks into `posts_request_ids` and `posts_results` to get values before
 and after the posts / found posts queries run. It stores a list of
 post_ids and the found posts value in object cache. This results in no
 more queries running if value is in cache.

 This plugin relays these two filters to do the caching. However, if you
 run a query, with fields 'ids' or 'id=>parent', neither of these filters
 are run as both return early. Now these was a new filter added in 4.6
 called `posts_pre_query` that runs before all types of queries. This can
 be used to load posts in from another source and stop queries from
 running, similar to `posts_request_ids`. However to be able to cache the
 values, there needs to be a filter that runs after values are set. This
 new filter `post_query_return` fixes this issue and adds a filter that
 runs, no matter the return type.

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


More information about the wp-trac mailing list