Make WordPress Core


Ignore:
Timestamp:
06/14/2021 08:38:38 PM (5 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.

File:
1 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 ) {
Note: See TracChangeset for help on using the changeset viewer.