Created
November 9, 2020 12:21
-
-
Save jchristopher/5816efcc2b2a86bea2da3c7d0c73a636 to your computer and use it in GitHub Desktop.
Conditionally remove an Engine Source before searching in SearchWP
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 | |
// Conditionally remove a SearchWP Engine Source. | |
add_filter( 'searchwp\query\before', function( $query ) { | |
// Applies only if `myflag` GET variable exists. | |
if ( ! isset( $_GET['myflag'] ) ) { | |
return; | |
} | |
// Remove Posts from Engine. | |
$source = \SearchWP\Utils::get_post_type_source_name( 'post' ) | |
$query->get_engine()->remove_source( $source ); | |
}, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment