Skip to content

Commit 73c234a

Browse files
committed
Use cleaned slug to query for template part post
1 parent f7d3945 commit 73c234a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/block-library/src/template-part/edit/use-template-part-post.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* WordPress dependencies
33
*/
44
import { useSelect } from '@wordpress/data';
5+
import { cleanForSlug } from '@wordpress/url';
56

67
export default function useTemplatePartPost( postId, slug, theme ) {
78
return useSelect(
@@ -22,18 +23,19 @@ export default function useTemplatePartPost( postId, slug, theme ) {
2223
// load the auto-draft created from the
2324
// relevant file.
2425
if ( slug && theme ) {
26+
const cleanedSlug = cleanForSlug( slug );
2527
const posts = select( 'core' ).getEntityRecords(
2628
'postType',
2729
'wp_template_part',
2830
{
2931
status: [ 'publish', 'auto-draft' ],
30-
slug,
32+
slug: cleanedSlug,
3133
theme,
3234
}
3335
);
3436
const foundPosts = posts?.filter(
3537
( post ) =>
36-
post.slug === slug &&
38+
post.slug === cleanedSlug &&
3739
post.meta &&
3840
post.meta.theme === theme
3941
);

0 commit comments

Comments
 (0)