-
-
Save searchwpgists/087d5d3d5b47b2e38c8062f80d7ef04f 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