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 7ef0f705da2dc9..73e027f27eb364 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 );