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/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.