Make WordPress Core


Ignore:
Timestamp:
06/10/2022 03:45:45 PM (3 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php

    r49955 r53485  
    5959
    6060        $query_args = array(
    61             'post_type'           => $post_types,
    62             'post_status'         => 'publish',
    63             'paged'               => (int) $request['page'],
    64             'posts_per_page'      => (int) $request['per_page'],
    65             'ignore_sticky_posts' => true,
    66             'fields'              => 'ids',
     61            'post_type'              => $post_types,
     62            'post_status'            => 'publish',
     63            'paged'                  => (int) $request['page'],
     64            'posts_per_page'         => (int) $request['per_page'],
     65            'ignore_sticky_posts'    => true,
    6766        );
    6867
     
    8483
    8584        $query     = new WP_Query();
    86         $found_ids = $query->query( $query_args );
     85        $posts     = $query->query( $query_args );
     86        // Querying the whole post object will warm the object cache, avoiding an extra query per result.
     87        $found_ids = wp_list_pluck( $posts, 'ID' );
    8788        $total     = $query->found_posts;
    8889
Note: See TracChangeset for help on using the changeset viewer.