Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Block Library - Query Loop]: Pass extra query args in REST API call for accurate preview for extenders #44093

Merged
merged 1 commit into from
Sep 13, 2022
Merged
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
13 changes: 12 additions & 1 deletion packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export default function PostTemplateEdit( {
inherit,
taxQuery,
parents,
pages,
// We gather extra query args to pass to the REST API call.
// This way extenders of Query Loop can add their own query args,
// and have accurate previews in the editor.
// Noting though that these args should either be supported by the
// REST API or be handled by custom REST filters like `rest_{$this->post_type}_query`.
...restQueryArgs
} = {},
queryContext = [ { page: 1 } ],
templateSlug,
Expand Down Expand Up @@ -178,7 +185,10 @@ export default function PostTemplateEdit( {
// block's postType, which is passed through block context.
const usedPostType = previewPostType || postType;
return {
posts: getEntityRecords( 'postType', usedPostType, query ),
posts: getEntityRecords( 'postType', usedPostType, {
...query,
...restQueryArgs,
} ),
blocks: getBlocks( clientId ),
};
},
Expand All @@ -198,6 +208,7 @@ export default function PostTemplateEdit( {
templateSlug,
taxQuery,
parents,
restQueryArgs,
previewPostType,
categories,
categorySlug,
Expand Down