Make WordPress Core

Changeset 51144


Ignore:
Timestamp:
06/14/2021 08:38:38 PM (2 years ago)
Author:
jorbin
Message:

Block Editor: Prevent duplicate queries

When passing args to WP_Query::__construct method (in this case, but creating a new WP_Query, this one internally executes the WP_Query::get_posts method and stores the result in the WP_Query::posts property. When calling the WP_Query::get_posts again, the same SQL query gets executed, and the result is again stored in the WP_Query::posts property.

This was introduced in [51003].

Props david.binda, jorbin.
Fixes #53280. See #53176.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r51003 r51144  
    8989    $template_query = new WP_Query( $wp_query_args );
    9090    $query_result   = array();
    91     foreach ( $template_query->get_posts() as $post ) {
     91    foreach ( $template_query->posts as $post ) {
    9292        $template = _build_template_result_from_post( $post );
    9393
     
    131131    );
    132132    $template_query       = new WP_Query( $wp_query_args );
    133     $posts                = $template_query->get_posts();
     133    $posts                = $template_query->posts;
    134134
    135135    if ( count( $posts ) > 0 ) {
  • trunk/src/wp-includes/theme-templates.php

    r51003 r51144  
    5050    );
    5151    $check_query      = new WP_Query( $check_query_args );
    52     $posts            = $check_query->get_posts();
     52    $posts            = $check_query->posts;
    5353
    5454    if ( count( $posts ) > 0 ) {
     
    6060            $query                       = new WP_Query( $query_args );
    6161            $suffix++;
    62         } while ( count( $query->get_posts() ) > 0 );
     62        } while ( count( $query->posts ) > 0 );
    6363        $override_slug = $alt_post_name;
    6464    }
Note: See TracChangeset for help on using the changeset viewer.