WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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" />

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;
share|improve this question
up vote 6 down vote accepted


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


<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

share|improve this answer
Works great, thanks! Is there a way to get it to return related pages as well? – Zach Shallbetter Mar 22 '11 at 17:09
Arrayed input values won't work with the GET method, i'd be surprised if that code is actually doing what you think it is.. – t31os Mar 22 '11 at 17:20
My mistake, it works when used alongside the filter from the user's previous question, disregard above comment. – t31os Mar 22 '11 at 17:25

You could do it like this to switch between a singular set type and any..

<input type="hidden" name="post_type" value="software" />
<label for="post_type">Search all</label>
<input type="checkbox" name="post_type" value="any" />

Unchecked searches your specific type, checked sets the post type to any..

share|improve this answer
This is just an additional tip to compliment Bainternet's answer. ;) – t31os Mar 22 '11 at 17:30

Your Answer


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.