Skip to content
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
[Block Library - Query Loop]: Pass extra query args in REST API call …
…for accurate preview for extenders
  • Loading branch information
ntsekouras committed Sep 12, 2022
commit 058d7dc50dedda9c28b403c5fb48a25329b77735
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