Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active March 16, 2022 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searchwpgists/d742bc89f837b1996aac0454533350fa to your computer and use it in GitHub Desktop.
Save searchwpgists/d742bc89f837b1996aac0454533350fa 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