Skip to content

Commit

Permalink
Post template block: Adjust the editor preview on taxonomy archive te…
Browse files Browse the repository at this point in the history
…mplates

Ensure that the preview of the post template block in the editor shows the correct posts on tag- and post format archive templates, when the query loop block is set to inherit the query from the template.

Co-authored-by: carolinan <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent 1ec454c commit 7c7c206
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c7c206

Please sign in to comment.