Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active July 10, 2019 14:20
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 jchristopher/9d4b9838126b13fff590931746740772 to your computer and use it in GitHub Desktop.
Save jchristopher/9d4b9838126b13fff590931746740772 to your computer and use it in GitHub Desktop.
Tell FacetWP to skip SearchWP when an empty s query parameter is passed
<?php
// Tell FacetWP to disregard SearchWP if the search query is empty.
add_filter( 'facetwp_facets', function( $facets ) {
if ( ! isset( $_REQUEST['s'] ) || ! empty( $_REQUEST['s'] ) || empty( $facets ) || ! is_array( $facets ) ) {
return $facets;
}
foreach ( $facets as $key => $facet ) {
if ( 'search' !== $facet['type'] ) {
continue;
}
// Because there's an empty s query parameter we can just tell FacetWP
// that SearchWP should be disregarded and to fall back to WP native handling.
$facets[ $key ]['search_engine'] = '';
}
return $facets;
}, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment