diff --git a/packages/block-library/src/query-loop/edit.js b/packages/block-library/src/query-loop/edit.js index 06a7949a87e4d..d6d22c5365821 100644 --- a/packages/block-library/src/query-loop/edit.js +++ b/packages/block-library/src/query-loop/edit.js @@ -26,6 +26,7 @@ export default function QueryLoopEdit( { tagIds = [], order, orderBy, + author, } = {}, queryContext, }, @@ -45,6 +46,9 @@ export default function QueryLoopEdit( { if ( perPage ) { query.per_page = perPage; } + if ( author ) { + query.author = author; + } return { posts: select( 'core' ).getEntityRecords( 'postType', @@ -54,7 +58,17 @@ export default function QueryLoopEdit( { blocks: select( 'core/block-editor' ).getBlocks( clientId ), }; }, - [ perPage, page, offset, categoryIds, tagIds, order, orderBy, clientId ] + [ + perPage, + page, + offset, + categoryIds, + tagIds, + order, + orderBy, + clientId, + author, + ] ); const blockContexts = useMemo( diff --git a/packages/block-library/src/query-loop/index.php b/packages/block-library/src/query-loop/index.php index 45c1622627e29..78660188163c2 100644 --- a/packages/block-library/src/query-loop/index.php +++ b/packages/block-library/src/query-loop/index.php @@ -44,6 +44,9 @@ function render_block_core_query_loop( $attributes, $content, $block ) { if ( isset( $block->context['query']['perPage'] ) ) { $query['posts_per_page'] = $block->context['query']['perPage']; } + if ( isset( $block->context['query']['author'] ) ) { + $query['author'] = $block->context['query']['author']; + } } $posts = get_posts( $query ); diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index a4d39f0c7b3dd..ece5a390a5f0f 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -14,7 +14,8 @@ "categoryIds": [], "tagIds": [], "order": "desc", - "orderBy": "date" + "orderBy": "date", + "author": null } } }, diff --git a/packages/block-library/src/query/edit/query-inspector-controls.js b/packages/block-library/src/query/edit/query-inspector-controls.js index 50e7a38ea7359..ec6a28d672189 100644 --- a/packages/block-library/src/query/edit/query-inspector-controls.js +++ b/packages/block-library/src/query/edit/query-inspector-controls.js @@ -4,18 +4,30 @@ import { PanelBody, QueryControls } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; +import { useSelect } from '@wordpress/data'; export default function QueryInspectorControls( { query, setQuery } ) { - const { order, orderBy } = query; + const { order, orderBy, author: selectedAuthorId } = query; + const { authorList } = useSelect( ( select ) => { + const { getEntityRecords } = select( 'core' ); + return { + authorList: getEntityRecords( 'root', 'user', { per_page: -1 } ), + }; + }, [] ); return ( - + setQuery( { order: value } ) } onOrderByChange={ ( value ) => setQuery( { orderBy: value } ) } + onAuthorChange={ ( value ) => + setQuery( { + author: value !== '' ? +value : undefined, + } ) + } /> diff --git a/packages/e2e-tests/fixtures/blocks/core__query.json b/packages/e2e-tests/fixtures/blocks/core__query.json index e06e002a5a314..d488279262312 100644 --- a/packages/e2e-tests/fixtures/blocks/core__query.json +++ b/packages/e2e-tests/fixtures/blocks/core__query.json @@ -11,7 +11,8 @@ "categoryIds": [], "tagIds": [], "order": "desc", - "orderBy": "date" + "orderBy": "date", + "author": null } }, "innerBlocks": [],