<?php
/** return exact matches for keyword searched in auto complete **/
add_filter( 'facetwp_wpdb_sql', function( $sql, $facet ) {
if ( 'keywords' == $facet['name'] ) {
global $wpdb;
$facet = $params['facet'];
$selected_values = $facet['selected_values'];
$selected_values = is_array( $selected_values ) ? $selected_values[0] : $selected_values;
$selected_values = stripslashes( $selected_values );
if ( empty( $selected_values ) ) {
return $sql;
}
$sql = "
SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index
WHERE facet_name = %s AND facet_display_value LIKE %s";
$sql = $wpdb->prepare( $sql, $facet['name'], $selected_values );
}
return $sql;
}, 10, 2 );