Skip to content

Commit

Permalink
[Block Library - Query Loop]: Pass extra query args in REST API call …
Browse files Browse the repository at this point in the history
…for accurate preview for extenders (#44093)
  • Loading branch information
ntsekouras authored Sep 13, 2022
1 parent 400647a commit e00cd51
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit e00cd51

Please sign in to comment.