From f90acdff2b48d73234ce831fabdf72662772c5d6 Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 6 Sep 2022 15:59:36 +0200 Subject: [PATCH] POC: Add query.entityRecordsArgs filter --- packages/block-library/src/post-template/edit.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-template/edit.js b/packages/block-library/src/post-template/edit.js index c88e8e3a9c497f..cd2ce77163d1d5 100644 --- a/packages/block-library/src/post-template/edit.js +++ b/packages/block-library/src/post-template/edit.js @@ -7,6 +7,7 @@ import classnames from 'classnames'; * WordPress dependencies */ import { memo, useMemo, useState } from '@wordpress/element'; +import { applyFilters } from '@wordpress/hooks'; import { useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { @@ -159,9 +160,22 @@ export default function PostTemplateEdit( { } // When we preview Query Loop blocks we should prefer the current // block's postType, which is passed through block context. + const usedPostType = previewPostType || postType; + + const { + postType: post, + usedPostType: usedPost, + query: queryObj, + } = applyFilters( 'query.entityRecordsArgs', { + postType: 'postType', + usedPostType, + query, + clientId, + } ); + return { - posts: getEntityRecords( 'postType', usedPostType, query ), + posts: getEntityRecords( post, usedPost, queryObj ), blocks: getBlocks( clientId ), }; },