Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created February 8, 2022 14:31
Show Gist options
  • Save searchwpgists/a14a1d7bd9af92876a8fcbddee635619 to your computer and use it in GitHub Desktop.
Save searchwpgists/a14a1d7bd9af92876a8fcbddee635619 to your computer and use it in GitHub Desktop.
Limit SearchWP results to Posts and Pages
<?php
// Limit SearchWP results to Posts and Pages.
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
$mod = new \SearchWP\Mod();
$mod->set_where( [ [
'column' => 'source',
'value' => [
\SearchWP\Utils::get_post_type_source_name( 'post' ),
\SearchWP\Utils::get_post_type_source_name( 'page' )
],
'compare' => 'IN',
] ] );
$mods[] = $mod;
return $mods;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment