I have a custom post type named projects and a taxonomy named type and some terms of that taxonomy like research, work, personal in which a project can belong or not. I want to create a wordpress custom search for projects and a dropdown menu with all the terms of my taxonomy.
In order to select only projects I was thinking to use something like this in my function.php file:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'projects');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
And to create a dropdown menu with type taxonomy terms I was thinking to use something like this in my searchform.php file:
<label for="type">Type:</label>
<select id="type" name="type">
<?php $project_types = get_categories('taxonomy=type'); ?>
<option value="">All</option>
<?php foreach ($project_types as $project_type) { ?>
<option value="<?php echo $project_type->term_id; ?>">
<?php echo $project_type->name; ?>
</option>
<?php } ?>
</select>
They work individually but I don't know how to make them work together! I don't know how to handle the variable passed through the form into the function SearchFilter.
Thank you in advance for help!