I am using WordPress and have a search box in the header. It searches on the basis of posts. Now I want to modify this search box with a cities drop down search box. I also added a new cities table in the database. I need to run the search box on the basis of cities.
You can simply add following code in your functions.php file in your WordPress theme directory.
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('trip'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
Here trip is my custom post type and now default search function of WordPress will only search in custom post type trip.
You can modify it according to your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With