REST API: Improve post cache priming in WP_REST_Post_Search_Handler class.

In the `WP_REST_Post_Search_Handler` class, ensure that post, post meta and term caches are correctly primed when performing a search.

Props furi3r, spacedmonkey, TimothyBlynJacobs, audrasjb, peterwilsoncc. 
Fixes #55674.


Built from https://develop.svn.wordpress.org/trunk@53485


git-svn-id: http://core.svn.wordpress.org/trunk@53074 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2022-06-10 15:47:08 +00:00
parent a29c6663fd
commit c8f31dc0c0
2 changed files with 9 additions and 8 deletions

View File

@ -58,12 +58,11 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
}
$query_args = array(
'post_type' => $post_types,
'post_status' => 'publish',
'paged' => (int) $request['page'],
'posts_per_page' => (int) $request['per_page'],
'ignore_sticky_posts' => true,
'fields' => 'ids',
'post_type' => $post_types,
'post_status' => 'publish',
'paged' => (int) $request['page'],
'posts_per_page' => (int) $request['per_page'],
'ignore_sticky_posts' => true,
);
if ( ! empty( $request['search'] ) ) {
@ -83,7 +82,9 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
$query_args = apply_filters( 'rest_post_search_query', $query_args, $request );
$query = new WP_Query();
$found_ids = $query->query( $query_args );
$posts = $query->query( $query_args );
// Querying the whole post object will warm the object cache, avoiding an extra query per result.
$found_ids = wp_list_pluck( $posts, 'ID' );
$total = $query->found_posts;
return array(

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53484';
$wp_version = '6.1-alpha-53485';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.