<?php
// Without this snippet, the Autocomplete facet's SQL is using " LIKE '%value%'", which returns partial matches.
// With the snippet, it will use " LIKE 'value%'", resulting in only matches in the filtered post results that start with the entered value.
// For exact matches, see:
// https://gist.facetwp.com/gist/facetwp-autocomplete-facet-return-only-results-matching-the-exact-value-entered/
add_filter( 'facetwp_wpdb_sql', function( $sql, $facet ) {
if ( 'my_autocomplete' == $facet['name'] ) {
global $wpdb;
$sql = $wpdb->remove_placeholder_escape( $sql );
$sql = str_replace("LIKE '%", "LIKE '", $sql);
}
return $sql;
}, 10, 2 );