diff --git a/lib/template-parts.php b/lib/template-parts.php index 464200f66d000a..da1407ed667e07 100644 --- a/lib/template-parts.php +++ b/lib/template-parts.php @@ -138,7 +138,7 @@ function filter_rest_wp_template_part_query( $args, $request ) { $tax_query = isset( $args['tax_query'] ) ? $args['tax_query'] : array(); $tax_query[] = array( 'taxonomy' => 'wp_theme', - 'field' => 'slug', + 'field' => 'name', 'terms' => $request['theme'], ); diff --git a/packages/block-library/src/template-part/edit/use-template-part-post.js b/packages/block-library/src/template-part/edit/use-template-part-post.js index fed17e7a4cd77a..5546e6ca7f0172 100644 --- a/packages/block-library/src/template-part/edit/use-template-part-post.js +++ b/packages/block-library/src/template-part/edit/use-template-part-post.js @@ -23,6 +23,8 @@ export default function useTemplatePartPost( postId, slug, theme ) { // load the auto-draft created from the // relevant file. if ( slug && theme ) { + const currentTheme = select( 'core' ).getCurrentTheme() + ?.stylesheet; const cleanedSlug = cleanForSlug( slug ); const posts = select( 'core' ).getEntityRecords( 'postType', @@ -30,7 +32,7 @@ export default function useTemplatePartPost( postId, slug, theme ) { { status: [ 'publish', 'auto-draft' ], slug: cleanedSlug, - theme, + theme: currentTheme, } ); diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index a960aa969bc906..313ef8a85d319b 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -28,7 +28,7 @@ function render_block_core_template_part( $attributes ) { 'tax_query' => array( array( 'taxonomy' => 'wp_theme', - 'field' => 'slug', + 'field' => 'name', 'terms' => $attributes['theme'], ), ),