From 5d9ca9dc6825d7826c24fe2ff10f31fd95588746 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Mon, 14 Jun 2021 20:39:57 +0000 Subject: [PATCH] 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 --- wp-includes/block-template-utils.php | 4 ++-- wp-includes/theme-templates.php | 4 ++-- wp-includes/version.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index fa32393290..ecdd8ec8fd 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -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] ); diff --git a/wp-includes/theme-templates.php b/wp-includes/theme-templates.php index 5cce35cd99..f5e03c5786 100644 --- a/wp-includes/theme-templates.php +++ b/wp-includes/theme-templates.php @@ -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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4165cb5836..40fdbd3dca 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.