diff --git a/packages/block-library/src/post-template/edit.js b/packages/block-library/src/post-template/edit.js index a9e279ee2c305..c58990233f361 100644 --- a/packages/block-library/src/post-template/edit.js +++ b/packages/block-library/src/post-template/edit.js @@ -119,6 +119,15 @@ export default function PostTemplateEdit( { _fields: [ 'id' ], slug: templateSlug.replace( 'category-', '' ), } ); + const templateTag = + inherit && + templateSlug?.startsWith( 'tag-' ) && + getEntityRecords( 'taxonomy', 'post_tag', { + context: 'view', + per_page: 1, + _fields: [ 'id' ], + slug: templateSlug.replace( 'tag-', '' ), + } ); const query = { offset: offset || 0, order, @@ -182,6 +191,16 @@ export default function PostTemplateEdit( { postType = query.postType; } else if ( templateCategory ) { query.categories = templateCategory[ 0 ]?.id; + } else if ( templateTag ) { + query.tags = templateTag[ 0 ]?.id; + } else if ( + templateSlug?.startsWith( 'taxonomy-post_format' ) + ) { + // Get the post format slug from the template slug by removing the prefix. + query.format = templateSlug.replace( + 'taxonomy-post_format-post-format-', + '' + ); } } // When we preview Query Loop blocks we should prefer the current