I'm trying to create a custom search form that searches a custom post type that I have created.

The form would need to search two custom taxonomies (similar to tags and categories) and the body text of the post.

There would be a search input that would search the body text and tags and a dropdown that would filter by category (Any, Category 1, Category 2, Category 3).

What kind of templates would I need to make and what kind of code would this require?

Thanks a ton!

  • 1
    Sorry, this is not a place where you can post a wish list for code. What have you tried? – s_ha_dum Apr 4 '14 at 16:33

Use pre_get_posts to filter search results:

function search_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
      $query->set('post_type', 'custom_post_type_name');
      $query->set('cat', intval($_POST['cat']); // assuming you have a select with categories with name "cat" 

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.