Make WordPress Core

Opened 7 years ago

Closed 14 months ago

#41700 closed enhancement (maybelater)

New filter return in WP_Query

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


WP_Query as multiple return points in get_posts method. This makes adding caching or generally short circuiting, hard. When fields 'ids' or 'id=>parents' many of the filters are bypassed. There should be a filter that all return types run through.

Attachments (2)

41700.diff (1.8 KB) - added by spacedmonkey 7 years ago.
41700.2.diff (1.8 KB) - added by spacedmonkey 7 years ago.

Download all attachments as: .zip

Change History (4)

7 years ago

7 years ago

#1 @spacedmonkey
7 years ago

I have a plugin that caches the result of WP_Query called 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.

#2 @spacedmonkey
14 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

Making this as maybe later.

Note: See TracTickets for help on using tickets.