Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add search in Query block
  • Loading branch information
ntsekouras committed Sep 10, 2020
commit a639ba3a3861695b4d1ccd0bb0f344db10eb5dd9
5 changes: 5 additions & 0 deletions packages/block-library/src/query-loop/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function QueryLoopEdit( {
order,
orderBy,
author,
search,
} = {},
queryContext,
},
Expand All @@ -49,6 +50,9 @@ export default function QueryLoopEdit( {
if ( author ) {
query.author = author;
}
if ( search ) {
query.search = search;
}
return {
posts: select( 'core' ).getEntityRecords(
'postType',
Expand All @@ -68,6 +72,7 @@ export default function QueryLoopEdit( {
orderBy,
clientId,
author,
search,
]
);

Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/query-loop/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ function render_block_core_query_loop( $attributes, $content, $block ) {
if ( isset( $block->context['query']['author'] ) ) {
$query['author'] = $block->context['query']['author'];
}
if ( isset( $block->context['query']['search'] ) ) {
$query['s'] = $block->context['query']['search'];
}
}

$posts = get_posts( $query );
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"tagIds": [],
"order": "desc",
"orderBy": "date",
"author": null
"author": null,
"search": ""
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/query/edit/query-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Dropdown,
ToolbarButton,
RangeControl,
TextControl,
FormTokenField,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -113,6 +114,13 @@ export default function QueryToolbar( { query, setQuery } ) {
onChange={ onTagsChange }
/>
) }
<TextControl
label={ __( 'Search' ) }
value={ query.search }
onChange={ ( value ) =>
setQuery( { search: value } )
}
/>
</>
) }
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/fixtures/blocks/core__query.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"tagIds": [],
"order": "desc",
"orderBy": "date",
"author": null
"author": null,
"search": ""
}
},
"innerBlocks": [],
Expand Down