From 058d7dc50dedda9c28b403c5fb48a25329b77735 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 12 Sep 2022 17:55:29 +0300 Subject: [PATCH] [Block Library - Query Loop]: Pass extra query args in REST API call for accurate preview for extenders --- packages/block-library/src/post-template/edit.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-template/edit.js b/packages/block-library/src/post-template/edit.js index a490a6674bf21..024b3de98db19 100644 --- a/packages/block-library/src/post-template/edit.js +++ b/packages/block-library/src/post-template/edit.js @@ -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, @@ -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 ), }; }, @@ -198,6 +208,7 @@ export default function PostTemplateEdit( { templateSlug, taxQuery, parents, + restQueryArgs, previewPostType, categories, categorySlug,