Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
search term highlighting elasticpress
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;
}
);
@tott

This comment has been minimized.

Copy link
Owner Author

commented Sep 5, 2019

this will add highlight results in the elasticsearch response "highlight": { "post_title": [ "<strong style="background:yellow">Hello</strong> world!" ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.