mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51144 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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] );
|
||||
|
||||
Reference in New Issue
Block a user