Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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
add comment

1 Answer

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 }?>
    </select>
    <input type="submit" id="searchsubmit" value="Search Help" />
</form>
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 }?> –  user205215 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. –  user205215 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> –  user205215 Dec 21 '12 at 11:20
show 1 more comment

Your Answer

 
discard

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.