Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"align": [ "wide", "full" ],
"html": false,
"layout": true,
"interactivity": true
"interactivity": true,
"contentRole": true
},
"editorStyle": "wp-block-query-editor"
}
11 changes: 10 additions & 1 deletion packages/block-library/src/query/edit/pattern-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Comment on lines +46 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working pretty well for me, and I think the trade off (that it might reduce the number of available patterns) is probably worth it.

Do you think there's a case for best practice eduction that Query patterns should ideally be wrapped in a Query block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. Conceivably you may want to create a complex pattern with a query in it, or even multiple queries. I think there's a place for those, but they aren't viable as replacements for a single Query block.

Comment on lines +46 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey folks! 👋

I’m maintaining Sensei LMS and noticed that one of our blocks (block variation of core/query) stopped showing the “Choose” patterns button, and it looks like this change is related. For context, the custom patterns are registered here. Could you give me a hand with finding a solution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1r0 would you be able to create a new issue for this and then link to it from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think the problem might be we're filtering for whatever variation is active, so you won't get other variations or the default query block in the results. We should probably filter for all instances of query block, whatever the variation. I'll try and get a fix up soon!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you so much for the quick reaction, @tellthemachines!


return rootBlockPatterns;
}

export default function PatternSelection( {
Expand Down
Loading