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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ registerBlockVariation( 'core/query', {
} );
```

In this way, the users won't have to choose the custom `postType` from the dropdown, and be already presented with the correct configuration. However, you might ask, how is a user going to find and insert this variation? Good question! To enable this, you should add:
In this way, the users won't have to choose the custom `postType` from the dropdown, and be already presented with the correct configuration.

A variation's `query` replaces the block's default `query` object instead of merging into it, so include every property your variation relies on, not only the ones you change. Always set `postType`: when it's missing, the block queries posts, both in the editor and on the front end.

However, you might ask, how is a user going to find and insert this variation? Good question! To enable this, you should add:

```js
{
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Query: Stop writing `excludeCurrent: null` into the `query` attribute of blocks that never had the key. The mount effect that clears a stale exclusion treated the absent key as stale, changing the serialized markup of every pre-existing Query block as soon as the editor opened it ([#82147](https://github.com/WordPress/gutenberg/pull/82147)).
- Icon: Preserve intrinsic SVG styles when applying block styles or rotation, and keep stroke widths scaling with the block's size for compatibility ([#78808](https://github.com/WordPress/gutenberg/pull/78808)).
- Image: Keep the selected image size, and re-point a media file or attachment page link, when an edit in the media editor saves to a new attachment. Cropping, rotating or flipping left the block rendering the full-size file while the size control still reported the size the user had chosen, and left the link pointing at the pre-edit image ([#82316](https://github.com/WordPress/gutenberg/pull/82316)).
- Query, Post Template: Treat a `query` attribute that omits `postType` as querying posts, matching `build_query_vars_from_query_block()` ([#82465](https://github.com/WordPress/gutenberg/pull/82465)).

### Internal

Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/post-template/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function PostTemplateEdit( {
query: {
perPage,
offset = 0,
postType,
// Match `build_query_vars_from_query_block()`, which queries posts when
// `query` has no post type.
postType = 'post',
order,
orderBy,
author,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export default function QueryInspectorControls( props ) {
orderBy,
author: authorIds,
pages,
postType,
// Match `build_query_vars_from_query_block()`, which queries posts when
// `query` has no post type.
postType = 'post',
perPage,
offset,
sticky,
Expand Down Expand Up @@ -172,7 +174,7 @@ export default function QueryInspectorControls( props ) {
isControlAllowed( allowedControls, 'excludeCurrent' );
const postTypeSingularName = useSelect(
( select ) =>
select( coreStore ).getPostType( postType )?.labels.singular_name,
select( coreStore ).getPostType( postType )?.labels?.singular_name,
[ postType ]
);

Expand Down
Loading