Skip to content

Commit

Permalink
Use cleaned slug to query for template part post
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen committed Sep 3, 2020
1 parent f7d3945 commit 73c234a
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
);
Expand Down

0 comments on commit 73c234a

Please sign in to comment.