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 am trying to figure out how to create a drop down to use as a filter with the search form. I would like the options to be the different post types. I've seen on other sites that -

<select name="posttype">
        <option name="product" value="product" style="color: #000;">Legal Documents</option>
        <option name="videos" value="videos">Legal Advice - Videos</option>
<option value="link">Legal Advice - Links</option>
<option value="text">Legal Advice - Articles</option>
         <option value="post_type_c">An Attorney</option>

What do I have to change or add to the search results page so that then correct post types are shown and filtere?

share|improve this question
Have you searched the site? There're plenty of questions for filtering the search results and extending the search form. Reminder: Please don't add random tags until you can't add more. Each tag has a description or at least an amount of questions that show you what this is about. – kaiser Dec 20 '12 at 7:49
I have tried searching the site and other sources and have not been able to find a solution. Do you know of a solution or reference link?????????? – mygm26 Dec 20 '12 at 8:10
Please see wordpress.stackexchange.com/questions/tagged/…, then update your question with your research efforts. – toscho Dec 20 '12 at 11:19
What do you mean? The code I have thus far is from the research I have done, that's what brought me this close to figuring it out. However it does not seem to work for me at all so that's why I am asking. – mygm26 Dec 20 '12 at 18:52

use for search this form with custom post type list

<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
        <input type="text" name="s" id="s" value="Enter keywords ..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/><br />
    <?php $types = get_post_types(); ?>

        <select name="posttype">
    <?php foreach ( $types as $type ) {?>
          <option name="<?php echo $type->singular_label ; ?>"
     value="<?php echo $type->singular_label ; ?>"><?php echo $type->singular_label ; ?></option>
    <?php }?>
    <input type="submit" id="searchsubmit" value="Search Help" />
share|improve this answer
Hi bhavik, thanks your reply however this does not work, it creates a empty drop down. Also with this code how would I then be able to change the label/text for each post type in the drop down? – mygm26 Dec 21 '12 at 10:28
<?php foreach ( $types as $type ) {?> <option name="<?php echo $type->singular_label ; ?>" value="<?php echo $type->singular_label ; ?>"> please change your label here </option> <?php }?> – Bhavik Patel Dec 21 '12 at 10:38
The original suggested code did not work for me but wouldn't the new suggestion make the label the same for all post types? – mygm26 Dec 21 '12 at 10:43
wait let me give you example. – Bhavik Patel Dec 21 '12 at 10:46
sorry i was wrong please use it <option name="<?php echo $type; ?>" value="<?php echo $type; ?>"><?php echo $type ;?></option> – Bhavik Patel Dec 21 '12 at 11:20

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.