From 09632f68d16ba6c68cdc0ab1be5a3ea683c7456c Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Wed, 18 Jan 2023 16:46:56 +0000 Subject: [PATCH 1/2] Now that WP_Query is cached, just load all templates. --- packages/block-library/src/template-part/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index f320362c32f1d4..86af2978966e80 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -29,7 +29,6 @@ function render_block_core_template_part( $attributes ) { array( 'post_type' => 'wp_template_part', 'post_status' => 'publish', - 'post_name__in' => array( $attributes['slug'] ), 'tax_query' => array( array( 'taxonomy' => 'wp_theme', @@ -37,11 +36,18 @@ function render_block_core_template_part( $attributes ) { 'terms' => $attributes['theme'], ), ), - 'posts_per_page' => 1, + 'posts_per_page' => -1, 'no_found_rows' => true, ) ); - $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null; + $template_part_post = null; + if ( $template_part_query->have_posts() ) { + foreach ( $template_part_query->posts as $template_post ) { + if ( $template_post->post_name === $attributes['slug'] ) { + $template_part_post = $template_post; + } + } + } if ( $template_part_post ) { // A published post might already exist if this template part was customized elsewhere // or if it's part of a customized template. From 77e904c71c3ace29d4debcc906cf9c795708904a Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Wed, 18 Jan 2023 17:00:12 +0000 Subject: [PATCH 2/2] Fix lint. --- packages/block-library/src/template-part/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 86af2978966e80..dccf5a562c7dd5 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -40,7 +40,7 @@ function render_block_core_template_part( $attributes ) { 'no_found_rows' => true, ) ); - $template_part_post = null; + $template_part_post = null; if ( $template_part_query->have_posts() ) { foreach ( $template_part_query->posts as $template_post ) { if ( $template_post->post_name === $attributes['slug'] ) {