Skip to content

Instantly share code, notes, and snippets.

@tott
Created September 11, 2019 10:28
Show Gist options
  • Save tott/1d557f1edba3aa7a3046b16761ff923d to your computer and use it in GitHub Desktop.
Save tott/1d557f1edba3aa7a3046b16761ff923d to your computer and use it in GitHub Desktop.
Set ElasticPress Exact match
function set_to_exact( $formatted_args, $args ) {
if ( ! empty( $formatted_args['query']['bool']['should'] ) ) {
$formatted_args['query']['bool']['must'] = $formatted_args['query']['bool']['should'];
$formatted_args['query']['bool']['must'][0]['multi_match']['operator'] = 'AND';
unset( $formatted_args['query']['bool']['should'] );
unset( $formatted_args["query"]["bool"]["must"][0]["multi_match"]["type"] );
}
return $formatted_args;
}
add_filter( 'ep_formatted_args', 'set_to_exact', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment