Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: Filter the search results based on block types #548

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ 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'];
$regex = substr( $regex, 1, -1 ); // Strips the ^$, which are not supported in ES regex (and not needed).

$filter['bool']['must'][] = [
'regexp' => [
'meta.wpop_contains_block_types.value.raw' => [
'value' => $regex,
'case_insensitive' => true,
],
],
];
}

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