I have made six custom taxonomies. I want to perform search using keyword and custom taxonomy in wordpress For eg: I want to have a dropdown with only four custom taxonomies(not all 6) and then filter the search based on the keyword and the custom taxonoy selected by me. In searchform.php, I pasted the code

<form method="get"  class="search-form" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
        <label for="search">Search:</label>
        <select id="search" class="select" title="Whole Site" name="cat">
                <option value="news">News Articles</option>
                <option value="publications">Publications</option>
                <option value="professionals">Professionals</option>
                <option value="company">Company</option>
        <div class="input-holder">
            <input type="text" placeholder="Enter keyword..." class="text" name="s" id="s">  
            <button type="submit" name="submit" class="submit">Search</button>

then in search.php , I retrieved the select value as $category_index=$_REQUEST['cat']; $ss=$_REQUEST['s'];

Further, I do not know how to filter.

  • What have you tried so far? Where in your coding efforts are you stuck? What are the results of your research prior to asking this question? Commented Jun 14, 2012 at 14:10
  • I have edited my question and added the code.
    – user930026
    Commented Jun 14, 2012 at 14:20

1 Answer 1


I would recommend you to use a hook for pre_get_posts action. This action is fired before appropriate posts are fetched from db. In this hook you can add extra parameters to your query and have influence on returned results. So the basic implementation of your hook could be like this:

add_action( 'pre_get_posts', 'wpse8170_pre_get_posts' );
function wpse8170_pre_get_posts( $query ) {
    if ( is_search() ) { // check if it is search page
        $query->set( 'arg', 'value' ); // add additional arguments to the query

Pay attention that arg and value parameters are generic and was mentioned as example. You have to use correct arg and value for your query. All list of available arguments for the query you can read in codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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