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