Created
August 31, 2020 12:48
-
-
Save jchristopher/2aa11e089b2e6253651348bc2c7aa631 to your computer and use it in GitHub Desktop.
Force quoted search logic in SearchWP when applicable
This file contains hidden or 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 | |
// Force multiple word searches to use quoted search logic if quotes are not added. | |
// NOTE: Quoted search must be enabled (checkbox on the Advanced tab) | |
add_filter( | |
'searchwp\query\search_string', | |
function( $search_string, $query ) { | |
// If there are already quotes, bail out. | |
if ( false !== strpos( $search_string, '"' ) ) { | |
return $search_string; | |
} | |
// If there's only one word, bail out. | |
if ( false === strpos( $search_string, ' ') ) { | |
return $search_string; | |
} | |
return '"' . $search_string . '"'; | |
}, | |
30, 2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment