facetwp hightlight searchwp keywords

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** use searchwp’s highlighter on the_excerpt output when using search facet with searchwp engine **/
add_filter( ‘the_excerpt’, function( $output ) {
$keywords = ”;
if ( isset( FWP()->facet->facets[‘search’] ) ) {
$keywords = FWP()->facet->facets[‘search’][‘selected_values’];
$keywords = is_array( $keywords ) ? implode( ‘ ‘, $keywords ) : $keywords;
}
if ( ! empty( $keywords ) && class_exists( ‘SearchWPHighlighter’ ) ) {
$highlighter = new SearchWPHighlighter();
$output = $highlighter->apply_highlight( $output, $keywords );
}
return $output;
}, 10, 2 );
{{/gist}}