Last active
July 10, 2019 14:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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