Skip to content

Commit

Permalink
Search: Filter the search results based on block types.
Browse files Browse the repository at this point in the history
If the `allowed_blocks` meta filter is set, we should also pass that through to the ElasticSearch filters.

See #540. Fixes #547.
  • Loading branch information
ryelle committed Jan 9, 2023
1 parent 8ac046d commit ed3d4a0
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ function modify_es_query_args( $es_query_args, $wp_query ) {
}
}

// If there is an allowed_blocks meta_query, use it to filter the ES query.
if ( isset( $meta_query['allowed_blocks'] ) && ! empty( $meta_query['allowed_blocks']['value'] ) ) {
// Parse it out of the regex format.
$regex = $meta_query['allowed_blocks']['value'];
$list = substr( $regex, 3, -6 );
$block_types = explode( '|', $list );

$filter['bool']['must'][] = [
'terms' => [ 'meta.wpop_contains_block_types.value.raw' => $block_types ],
];
}

$parser->add_query( $must_query, 'must' );
$parser->add_query( $should_query, 'should' );
$parser->add_filter( $filter );
Expand Down

0 comments on commit ed3d4a0

Please sign in to comment.