Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Force quoted search logic in SearchWP when applicable
<?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