0

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!

4

1 回答 1

0

我知道它可能已经过时了,但我正在谷歌搜索类似的东西,并在这里找到了您/我们的问题的解决方案:http: //fearlessflyer.com/how-to-create-an-advanced-search-form-for-wordpress/

于 2013-10-29T12:01:48.777 回答