Last active
March 9, 2021 16:53
-
-
Save jchristopher/75aa040286055a4daaded7c5be171192 to your computer and use it in GitHub Desktop.
Control SearchWP AND logic token threshold
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 | |
// 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