Forked from jchristopher/gist:676652d094264a3e8853
Created
September 25, 2017 21:20
-
-
Save gnanet/8c0781418fce05ba4632255e9d8c3b98 to your computer and use it in GitHub Desktop.
find out if there was an exact match of a SearchWP term
This file contains hidden or 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 | |
// 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