Skip to content

Commit

Permalink
fix logic for request template resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jan 10, 2024
1 parent 9a03348 commit 6067db6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,22 @@ export const getEditedPostTemplate = createRegistrySelector(
}

const post = select( editorStore ).getCurrentPost();
let slugToCheck;
// In `draft` status we might not have a slug available, so we use the `single`
// post type templates slug(ex page, single-post, single-product etc..).
// Pages do not need the `single` prefix in the slug to be prioritized
// through template hierarchy.
if ( post.slug ) {
slugToCheck =
post.type === 'page'
? `${ post.type }-${ post.slug }`
: `single-${ post.type }-${ post.slug }`;
} else {
slugToCheck =
post.type === 'page' ? 'page' : `single-${ post.type }`;
}
const defaultTemplateId = select( coreStore ).getDefaultTemplateId( {
slug: `${ post.type }-${ post.slug }`,
slug: slugToCheck,
} );
return select( coreStore ).getEditedEntityRecord(
'postType',
Expand Down

0 comments on commit 6067db6

Please sign in to comment.