WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#41700 new enhancement

New filter return in WP_Query

Reported by: spacedmonkey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 1.5
Component: Query Keywords: has-patch
Focuses: performance Cc:
PR Number:

Description

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 2 years ago.
41700.2.diff (1.8 KB) - added by spacedmonkey 2 years ago.

Download all attachments as: .zip

Change History (3)

@spacedmonkey
2 years ago

@spacedmonkey
2 years ago

#1 @spacedmonkey
2 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.

Note: See TracTickets for help on using tickets.