Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
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