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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user