Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
2  
Possible duplicate: wordpress.stackexchange.com/questions/2623/… –  developdaly Apr 7 '12 at 20:26
add comment

2 Answers

up vote 0 down vote accepted

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 }
endif;
share|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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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