Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
if( class_exists( 'SearchWP_Term_Highlight' ) ) {
// instantiate the highlighter
$searchwp_highlighter = new SearchWP_Term_Highlight();
// decipher the search query (NOTE: update the GET var if necessary)
$search_query = '';
if( isset( $_GET['swpquery'] ) && ! empty( $_GET['swpquery'] ) ) {
$search_query = sanitize_text_field( urldecode( $_GET['swpquery'] ) );
}
// define the content you want to highlight
$content_to_highlight = substr( $post->description,0,140 ) . "..";
// highlight the content
$highlighted_content = $searchwp_highlighter->apply_highlight( $content_to_highlight, $search_query );
echo $highlighted_content;
}
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.