0

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( '/' ) ); ?>">
    <fieldset>
        <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>
        </select>
        <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>
        </div>
    </fieldset>
</form>

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? – Johannes Pille Jun 14 '12 at 14:10
  • I have edited my question and added the code. – user930026 Jun 14 '12 at 14:20
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, privacy policy and cookie policy

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