FacetWP – preserve relevancy if both a search and proximity facet are in use

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

// Add to your (child) theme’s functions.php

add_filter( ‘facetwp_filtered_post_ids’, function( $post_ids ) {
$facets = FWP()->facet->facets;
if ( isset( $facets[‘keywords’] ) && ! empty( $facets[‘keywords’][‘selected_values’] ) ) {
remove_filter( ‘facetwp_filtered_post_ids’, [ FWP()->helper->facet_types[‘proximity’], ‘sort_by_distance’ ] );
}
return $post_ids;
}, 9 );

{{/gist}}