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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@50753 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2021-06-14 20:39:57 +00:00
parent b7489425cb
commit 5d9ca9dc68
3 changed files with 5 additions and 5 deletions

View File

@ -88,7 +88,7 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
$template_query = new WP_Query( $wp_query_args );
$query_result = array();
foreach ( $template_query->get_posts() as $post ) {
foreach ( $template_query->posts as $post ) {
$template = _build_template_result_from_post( $post );
if ( ! is_wp_error( $template ) ) {
@ -130,7 +130,7 @@ function get_block_template( $id, $template_type = 'wp_template' ) {
),
);
$template_query = new WP_Query( $wp_query_args );
$posts = $template_query->get_posts();
$posts = $template_query->posts;
if ( count( $posts ) > 0 ) {
$template = _build_template_result_from_post( $posts[0] );

View File

@ -49,7 +49,7 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID
),
);
$check_query = new WP_Query( $check_query_args );
$posts = $check_query->get_posts();
$posts = $check_query->posts;
if ( count( $posts ) > 0 ) {
$suffix = 2;
@ -59,7 +59,7 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID
$query_args['post_name__in'] = array( $alt_post_name );
$query = new WP_Query( $query_args );
$suffix++;
} while ( count( $query->get_posts() ) > 0 );
} while ( count( $query->posts ) > 0 );
$override_slug = $alt_post_name;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-beta1-51143';
$wp_version = '5.8-beta1-51144';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.