Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created April 12, 2022 14:34
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/b06e9e45b93029b148481fa8b8959546 to your computer and use it in GitHub Desktop.
Save searchwpgists/b06e9e45b93029b148481fa8b8959546 to your computer and use it in GitHub Desktop.
<?php
// @link https://searchwp.com/documentation/classes/searchwp-mod/
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
// Retrieve Source name to use with Mod.
$source = \SearchWP\Utils::get_post_type_source_name( 'post' );
// Build Mod to exclude Post ID 145 and Post ID 211.
$mod = new \SearchWP\Mod( $source );
$mod->set_where( [ [
'column' => 'id',
'value' => [ 145, 211 ],
'compare' => 'NOT IN',
'type' => 'NUMERIC',
] ] );
$mods[] = $mod;
return $mods;
}, 20, 2 );
// Execute search for 'coffee' using Mod enqueued above.
$search = new \SearchWP\Query( 'coffee' );
$results = $search->results; // Array of results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment