diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index c7b96df855807f..fe2a5f65aaebf1 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -759,7 +759,7 @@ An advanced block that allows displaying post types based on different query par - **Name:** core/query - **Category:** theme -- **Supports:** align (full, wide), interactivity, layout, ~~html~~ +- **Supports:** align (full, wide), contentRole, interactivity, layout, ~~html~~ - **Attributes:** enhancedPagination, namespace, query, queryId, tagName ## No Results diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index 6ccafc50c82017..33ba8bfd925ca8 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -53,7 +53,8 @@ "align": [ "wide", "full" ], "html": false, "layout": true, - "interactivity": true + "interactivity": true, + "contentRole": true }, "editorStyle": "wp-block-query-editor" } diff --git a/packages/block-library/src/query/edit/pattern-selection.js b/packages/block-library/src/query/edit/pattern-selection.js index 0c5d95d15206f2..b9f5efa5d8bc9a 100644 --- a/packages/block-library/src/query/edit/pattern-selection.js +++ b/packages/block-library/src/query/edit/pattern-selection.js @@ -43,7 +43,16 @@ export function useBlockPatterns( clientId, attributes ) { clientId, attributes ); - return usePatterns( clientId, blockNameForPatterns ); + const allPatterns = usePatterns( clientId, blockNameForPatterns ); + // Filter out any patterns that don't have Query as their root block + // so that a Query block is always replaced by another Query block. + const rootBlockPatterns = useMemo( () => { + return allPatterns.filter( ( pattern ) => { + return pattern.blocks?.[ 0 ]?.name === blockNameForPatterns; + } ); + }, [ allPatterns, blockNameForPatterns ] ); + + return rootBlockPatterns; } export default function PatternSelection( {