Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active March 9, 2021 16:53
Show Gist options
  • Save jchristopher/75aa040286055a4daaded7c5be171192 to your computer and use it in GitHub Desktop.
Save jchristopher/75aa040286055a4daaded7c5be171192 to your computer and use it in GitHub Desktop.
Control SearchWP AND logic token threshold
<?php
// Control SearchWP AND logic token threshold.
// @link https://searchwp.com/documentation/hooks/searchwp-query-logic-and-token_threshold/
add_filter( 'searchwp\query\logic\and\token_threshold', function( $threshold, $args ) {
// If the search contains 'coffee' allow up to 10 tokens for AND logic.
if ( in_array( 'coffee', $args['tokens'], true ) ) {
$threshold = 10;
}
// If the search contains 'soccer' disable AND logic token threshold.
if ( in_array( 'soccer', $args['tokens'], true ) ) {
$threshold = false;
}
return $threshold;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment