Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Search By Category in WordPress (2 Ways)

Do you want to add category specific search in WordPress?

Adding a search by category feature to WordPress lets your visitors quickly find what they’re looking for. You can add options to search specific blog categories, product categories, and more.

In this tutorial, we’ll show you how you can add a search by category feature to your WordPress site.

How to search by category in WordPress (2 ways)

Why Add Search By Category to WordPress?

A search by category feature allows your visitors to search specific website categories.

If you have a lot of content, then categories can help organize your content and make it easier for your visitors to find what they’re looking for.

You can add a category search feature to your archive pages to help your visitors quickly find what they’re looking for.

WordPress archive category search example

Category search can also be added to your online store, so visitors can quickly find the exact products they want.

Overall, this offers your visitors a better onsite experience and can help your WordPress website give off positive SEO signals like increased dwell time and lower bounce rate.

The best way to add a category search feature is by using a WordPress plugin.

We’re going to share two different WordPress search plugins that can help you customize WordPress search. Simply use the quick links below to choose the type of WordPress category search you want to add.

Method 1: Using SearchWP to Add Category Select Search Form to WordPress

SearchWP is the best search plugin for WordPress. It’s very easy to use and lets you add a category selection feature, giving your users control over their search results.

First, you need to install and activate the SearchWP plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, navigate to Settings » SearchWP. This brings up the main search settings menu.

SearchWP settings menu

You can adjust the search engine settings by clicking on ‘Posts’, ‘Pages’, or ‘Library’ drop downs.

Changing the ‘Weight Multiplier’ sliders customizes how the search engine values content. If you want the search engine to value page content higher than the title, then adjust the slider accordingly.

SearchWP save search engine

Once you’re done, make sure you click the ‘Save Engines’ button to generate your first search engine.

Next, we’re going to customize the search form to add a category selection option, so your visitors can decide which category they want to search.

To do this, you’ll need to add code to your WordPress files. If you haven’t done this before, then check out our guide on how to copy and paste code in WordPress.

You’ll need to copy and paste the following code and add it to your functions.php file, in a site-specific plugin, or by using a code snippets plugin.

function my_searchwp_get_search_form_with_categories_dropdown( $form ) {
	ob_start(); ?>
		<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
			<label>
				<span class="screen-reader-text">Search For</span>
				<input type="search" class="search-field" placeholder="Search..." value="<?php echo esc_attr( get_search_query() ); ?>" name="s" title="Search for:" />
			</label>
			<?php
				// for more information see http://codex.wordpress.org/Function_Reference/wp_dropdown_categories
				$swp_cat_dropdown_args = array(
						'show_option_all'  => __( 'Any Category' ),
						'name'             => 'swp_category_limiter',
					);
				wp_dropdown_categories( $swp_cat_dropdown_args );
			?>
			<input type="submit" class="search-submit" value="Search" />
		</form>
	<?php return ob_get_clean();
}

add_filter( 'get_search_form', 'my_searchwp_get_search_form_with_categories_dropdown' );

This code modifies the search form on your WordPress blog, and gives users a drop down box to select their preferred category.

After the code is added you can view any of your search forms, and you’ll see that a category search drop down has been added.

Select category drop down

You also use SearchWP to customize your WooCommerce product search pages. For more details, see our guide on how to make a smart WooCommerce product search.

Method 2: Using Ivory Search to Add Search By Category Form to WordPress

Ivory Search is another popular WordPress search plugin. It’s very easy to use and helps you simply control search categories across WordPress.

First thing you need to do is install the plugin. For more details, see our guide on how to install a WordPress plugin.

Once the plugin is activated, you’ll have a new WordPress menu item called ‘Ivory Search’.

Go to Ivory Search » Search Forms, then click the ‘Add New Search Form Button’.

Add new category search form

Now it’s time to start building your category search form.

First, give your search form a name. This name will not appear when you add the search feature to your website. It’s only for admin purposes.

Name category search form

Next, click the drop down in the ‘Post Types’ meta box. This brings up a menu to select the type of content you want to allow. You can add Posts, Pages, and Media to the search.

You can simply enable the toggle for the content types you want to allow.

Select post option for category search

After that, click the ‘Posts’ option to bring up the expanded menu. Then, turn on the ‘Search posts of only selected taxonomies’ toggle.

This allows you to select the WordPress categories you can add to search.

Choose WordPress search categories

Once you’ve selected the category or categories, click the ‘Save Form’ button.

Now, under your search form title, copy the shortcode and paste it into a text file.

Copy category search shortcode

This shortcode gives you the flexibility to add WordPress category search to any page, post, or widgetized area of your website.

All you have to do now is open the post, page, or widget where you want to add your category search and paste your shortcode. For more details, see our guide on how to add a shortcode in WordPress.

Add category search shortcode

After you click ‘Save’, the post or page will now have your active category search form.

You can add this shortcode to as many areas of your site as you’d like.

Category search form example

When a user searches with this form, they’ll only be able to view posts within the selected category.

In this case, visitors will only be able to view posts from the ‘Tutorials’ category.

Category search form results

If you want to create multiple different category searches, then follow the steps above to create another search form and embed the new shortcode into your site.

We hoped this article helped you add search by category in WordPress. You may also want to see our expert pick of the best WordPress plugins for businesses, and our comparison of the best email marketing services.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

18 CommentsLeave a Reply

  1. Hey help , I want to create a search box for web page and it should search in only one page category. How can i do that in wordpress.

  2. This is exactly what I was looking for! Needed a sidebar for a separate review section, with a search bar that only searched that separate section. So this was perfect

  3. Thanks for the support for this awesome plugin. i have tried the plugin, the search by name works fine but the category search is not showing any result. i guess it is not compatible with 3.5 — >3.8.
    i have tried changing “cat” to “category” but all to no avail . Any quick help will be hugely appreciated. Thanks in advance.

  4. After I installed this plugin, the original categories widget doesn’t work any more!
    Once I removed the plugin, it’s work again!
    I still can’t find the reason.

    Could someone tell me how to fix the problem?

    Thanks a lot!

  5. i run both regular search with google custom search, and the search category plugin, . i modified the searchform.php in order to have google search results ( with this shortcode ).
    When i use the search by category plugin the results are the same of the standard so they are not filtered obviously because i use in both case google custom search .
    so i would reset thestandard only for () for this plugin
    how can i Do?
    thanks

  6. Team,

    I tried the steps above, but when i added [sbc] in the text area, it just displayed that as a text instead of calling the search box. Am i missing something here.

    Else, also not sure where i can add the mentioned code in the theme template. Could someone help me with the specific theme file i need to edit.

    Thanks

  7. Oh I’m so glad to find this plugin! I think I need to keep looking though because I need to have it search specific pages on my site as well as some categories of posts.

  8. Search by category is only tested for WordPress version up to 3.4.2 – is it ok to install anyway? I use 3.5.0
    I really look forward to a functionality which will make it easier for my readers to browse and seach in my categories.
    Greetings Gitte

  9. I just did a review of different options for a client site and eventually installed the Search Everything plugin. It gives you the option to also configure what gets searched. And in this case I wanted to exclude a couple of categories.

  10. If no serious customization is needed, you could just use the following snippet in your searchform.php

    <form method="get" id="searchform" action="<?php echo home_url(); ?>">
    <input type="search" id="s" name="s" />
    <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
    </form>

  11. I use Relevanssi on one of my sites and it is great but I would love to add something like this to narrow search fields but rather than narrow by category. I’d like to narrow by custom taxonomy.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.