diff --git a/lib/template-loader.php b/lib/template-loader.php index e68f1740c711b..82a86e7a539e3 100644 --- a/lib/template-loader.php +++ b/lib/template-loader.php @@ -148,7 +148,7 @@ function create_auto_draft_for_template_part_block( $block ) { array( 'post_type' => 'wp_template_part', 'post_status' => array( 'publish', 'auto-draft' ), - 'name' => $block['attrs']['slug'], + 'title' => $block['attrs']['slug'], 'meta_key' => 'theme', 'meta_value' => $block['attrs']['theme'], 'posts_per_page' => 1, 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 7ef0f705da2dc..73e027f27eb36 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 @@ -2,6 +2,7 @@ * WordPress dependencies */ import { useSelect } from '@wordpress/data'; +import { cleanForSlug } from '@wordpress/url'; export default function useTemplatePartPost( postId, slug, theme ) { return useSelect( @@ -22,18 +23,19 @@ export default function useTemplatePartPost( postId, slug, theme ) { // load the auto-draft created from the // relevant file. if ( slug && theme ) { + const cleanedSlug = cleanForSlug( slug ); const posts = select( 'core' ).getEntityRecords( 'postType', 'wp_template_part', { status: [ 'publish', 'auto-draft' ], - slug, + slug: cleanedSlug, theme, } ); const foundPosts = posts?.filter( ( post ) => - post.slug === slug && + post.slug === cleanedSlug && post.meta && post.meta.theme === theme );