Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created May 28, 2020 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/11d5466096f88856322ecf58dc66dea9 to your computer and use it in GitHub Desktop.
Save mgibbs189/11d5466096f88856322ecf58dc66dea9 to your computer and use it in GitHub Desktop.
FacetWP - preserve relevancy if both a search and proximity facet are in use
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment