Skip to content

Commit

Permalink
change post type based on ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 29, 2024
1 parent caf5477 commit b0537eb
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ const postTypesWithoutParentTemplate = [

const authorizedPostTypes = [ 'page', 'post' ];

function getPostType( name ) {
function getPostType( name, postId ) {
let postType;
if ( name === 'navigation-item' ) {
postType = NAVIGATION_POST_TYPE;
} else if ( name === 'pattern-item' ) {
postType = PATTERN_TYPES.user;
} else if ( name === 'template-part-item' ) {
postType = TEMPLATE_PART_POST_TYPE;
} else if ( name === 'template-item' || name === 'templates' ) {
} else if ( name === 'templates' ) {
postType = /^\d+$/.test( postId )
? TEMPLATE_POST_TYPE
: '_wp_static_template';
} else if ( name === 'template-item' ) {
postType = TEMPLATE_POST_TYPE;
} else if ( name === 'static-template-item' ) {
postType = '_wp_static_template';
Expand All @@ -54,7 +58,7 @@ function getPostType( name ) {
export function useResolveEditedEntity() {
const { name, params = {}, query } = useLocation();
const { postId: _postId = query?.postId } = params; // Fallback to query param for postId for list view routes.
const _postType = getPostType( name );
const _postType = getPostType( name, _postId );

const homePage = useSelect( ( select ) => {
const { getHomePage } = unlock( select( coreDataStore ) );
Expand Down

0 comments on commit b0537eb

Please sign in to comment.