Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gnanet/8c0781418fce05ba4632255e9d8c3b98 to your computer and use it in GitHub Desktop.
Save gnanet/8c0781418fce05ba4632255e9d8c3b98 to your computer and use it in GitHub Desktop.
find out if there was an exact match of a SearchWP term
<?php
// find out if there was an exact match
global $wpdb;
if ( defined( 'SEARCHWP_DBPREFIX' ) && SEARCHWP_DBPREFIX ) {
$searchwp_terms_table = $wpdb->prefix . SEARCHWP_DBPREFIX . 'terms';
$search_query = sanitize_text_field( get_search_query() );
$search_sql = "SELECT id FROM {$searchwp_terms_table} WHERE term = %s";
$term_found = $wpdb->get_var( $wpdb->prepare( $search_sql, $search_query ) );
$exact_match = is_null( $term_found ) ? false : true;
if ( $exact_match ) {
echo 'Exact match!';
} else {
echo 'NOT exact match!';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment