I’m using bainternet’s method for searching custom post_types and it works great. However, I’ve recently been requested to return more than one “specific” post type and perhaps individual pages for a support section on our site.

I thought adding additional hidden fields would do it, but that didn’t work. And I have no clue how this will work with pages.

Any help would be appreciated!


In the template:

<form action="http://apollo.website.net/" id="searchform" method="get" role="search">
    <div><label for="s" class="screen-reader-text">Search for:</label>
    <input type="text" id="s" name="s" value="">
    <input type="submit" value="Search" id="searchsubmit">

    <input type="hidden" name="post_type" value="software" />
    </div>
</form>

In functions.php:

/* Custom Search Queries */
function SearchFilter($query) {
$post_type = $_GET['post_type'];
if (!$post_type) {
    $post_type="any";
}
if ($query->is_search) {
    $query->set('post_type', $post_type);
};
return $query;
} 

3 s
3

change

<input type="hidden" name="post_type" value="software" />

to

<input type="hidden" name="post_type[]" value="software" />
<input type="hidden" name="post_type[]" value="books" />

i have to run but this should work , just add as many hidden fields as you need for each post type

Leave a Reply

Your email address will not be published. Required fields are marked *