-
-
Save searchwpgists/032d2d1fa43dc435eb713e6e55d7b793 to your computer and use it in GitHub Desktop.
Conditionally remove an Engine Source before searching in SearchWP
This file contains 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