Add dropdown to search by all categories or define a specific category

Adding this snippet to your wordpress theme will allow users to search your website but also allow them to select a specific category as well. By modifying the arguments within "wp_dropdown_categories" you can exclude categories or even specify the specific order of categories within the list. The following options are available:

show_option_all, show_option_none, orderby, order, show_count, hide_empty, child_of, exclude, echo, selected, hierarchical, name, id, class, depth, tab_index, taxonomy, hide_if_empty

wordpress codex

<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
    <label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s" />
    in <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
    <input type="submit" id="searchsubmit" value="Search" />

Comments  Leave a Reply

  1. Not working with custom post typewith custom taxonomy

  2. stephen brunton October 2, 2018 at 9:14 am

    where would i add this code as this is exactly what im after

    1. Looks like you need to add it on a HTML widget.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!