From 2e9cf6a4e3484aa7833025ab2206bdfefa341f75 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 16 Sep 2025 14:38:02 +1000 Subject: [PATCH 1/3] Add contentRole to Query block --- docs/reference-guides/core-blocks.md | 2 +- packages/block-library/src/query/block.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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" } From baa8a32a8ced7db88743ff7eb5327bfcc8bc3a17 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 17 Sep 2025 10:49:46 +1000 Subject: [PATCH 2/3] Always replace a Query block with another Query block --- .../src/query/edit/pattern-selection.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/query/edit/pattern-selection.js b/packages/block-library/src/query/edit/pattern-selection.js index 0c5d95d15206f2..078a9d3fead5bd 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( { @@ -74,6 +83,18 @@ export default function PatternSelection( { blocks, attributes ); + // console.log( + // 'new blocks', + // newBlocks, + // 'query client ids', + // queryClientIds, + // 'pattern', + // pattern, + // 'blocks', + // blocks, + // 'attributes', + // attributes + // ); replaceBlock( clientId, newBlocks ); if ( queryClientIds[ 0 ] ) { selectBlock( queryClientIds[ 0 ] ); From 2a11acce4e8794b711b6c9cb5d594936af63d208 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 17 Sep 2025 12:45:27 +1000 Subject: [PATCH 3/3] remove console.log lol Co-authored-by: Ramon --- .../src/query/edit/pattern-selection.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/block-library/src/query/edit/pattern-selection.js b/packages/block-library/src/query/edit/pattern-selection.js index 078a9d3fead5bd..b9f5efa5d8bc9a 100644 --- a/packages/block-library/src/query/edit/pattern-selection.js +++ b/packages/block-library/src/query/edit/pattern-selection.js @@ -83,18 +83,6 @@ export default function PatternSelection( { blocks, attributes ); - // console.log( - // 'new blocks', - // newBlocks, - // 'query client ids', - // queryClientIds, - // 'pattern', - // pattern, - // 'blocks', - // blocks, - // 'attributes', - // attributes - // ); replaceBlock( clientId, newBlocks ); if ( queryClientIds[ 0 ] ) { selectBlock( queryClientIds[ 0 ] );