I was wondering does anyone know how I can modify the search so it searches a taxonomy?

at the moment it just looks for a product title, but not the taxonomy assigned to the post.

Please help


You need to change the query settings before it is run. I'm assuming that you have a search.php page, but if not I'll tell you where to put the code at the end.

In search.php add this to the very top of the file (above the get_header() call) -

$args = array(
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged,
    'post_type' => $post_type, // The post type that you wish to search
    $taxonomy => $term // Where $taxonomy is say 'cheese' and $term (must use the slug) is maybe 'cheddar'. Can be omitted if you do not actually wish to search taxonomy/terms. I think you can also pass $term as an array of terms - array('cheddar', 'brie', 'edam').

If you do not have search.php, nest the code as below and place it at the top of your index.php file -

if(is_search()) :
    { Code from above goes here }
| improve this answer | |
  • I don't understand what an array could do to it, but it doesn't seem to work, I also added $wp_query = new WP_Query($args); on the search.php file but with no luck – Val Apr 3 '12 at 15:57
  • I thought that if you had a search.php file Wordpress would automatically pass the $args, but perhaps not. It could be worth trying query_posts($args); directly under the $args array. – David Gard Apr 11 '12 at 13:58

You should search for duplicate questions, this question was asked here:

Include custom taxonomy term in search

The answer is: Use the Search Everything plugin

| 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.