Created
September 5, 2019 09:49
-
-
Save tott/9d061c750f0e80703390a1f5571cf7e3 to your computer and use it in GitHub Desktop.
search term highlighting elasticpress
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
add_filter( | |
'ep_formatted_args', | |
function( $formatted_args ) { | |
if ( ! empty( $_GET['s'] ) ) { | |
foreach ( [ 'post_title', 'post_excerpt', 'author_name', 'terms.post_tag.name', 'terms.category.name' ] as $field ) { | |
$formatted_args['highlight']['fields'][ $field ] = [ | |
'pre_tags' => [ '<strong style="background:yellow">' ], | |
'post_tags' => [ '</strong>' ], | |
'type' => 'plain', | |
]; | |
} | |
} | |
return $formatted_args; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this will add highlight results in the elasticsearch response
"highlight": { "post_title": [ "<strong style="background:yellow">Hello</strong> world!" ] }