Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created November 9, 2020 12:21
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 jchristopher/5816efcc2b2a86bea2da3c7d0c73a636 to your computer and use it in GitHub Desktop.
Save jchristopher/5816efcc2b2a86bea2da3c7d0c73a636 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