-
-
Save searchwpgists/248c0bd9a39efc7d085278b8c2420475 to your computer and use it in GitHub Desktop.
Limit SearchWP results to form field value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Limit SearchWP results to form field value. | |
// `sources` is a GET array of post type names. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
if ( empty( $_GET['sources'] ) ) { | |
return $mods; | |
} | |
$mod = new \SearchWP\Mod(); | |
$mod->set_where( [ [ | |
'column' => 'source', | |
'value' => array_map( function( $source ) { | |
return \SearchWP\Utils::get_post_type_source_name( $source ); | |
}, $_GET['sources'] ), | |
'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