Created
September 11, 2019 10:28
-
-
Save tott/1d557f1edba3aa7a3046b16761ff923d to your computer and use it in GitHub Desktop.
Set ElasticPress Exact match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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