Last active
April 22, 2020 17:54
-
-
Save mgibbs189/ab9ee109b0230198319326c9c6d901db to your computer and use it in GitHub Desktop.
FacetWP - support SearchWP term highlight
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
<?php | |
/** | |
* Modify the output HTML and highlighting all search terms | |
*/ | |
add_filter( 'facetwp_render_output', function( $output, $params ) { | |
$keywords = ''; | |
if ( isset( FWP()->facet->facets['keywords'] ) ) { | |
$keywords = FWP()->facet->facets['keywords']['selected_values']; | |
$keywords = is_array( $keywords ) ? implode( ' ', $keywords ) : $keywords; | |
} | |
if ( ! empty( $keywords ) && class_exists( 'SearchWPHighlighter' ) ) { | |
$highlighter = new SearchWPHighlighter(); | |
$output['template'] = $highlighter->apply_highlight( $output['template'], $keywords ); | |
} | |
return $output; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment