Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Create Advanced Search Form in WordPress for Custom Post Types

If you use custom post types, then you may want to create a form that allows visitors to search only that content. This can help people find what they are looking for and keep them on your site for longer.

Over the years, we have used custom post types on several of our websites to improve content organization. Additionally, we have added search forms specifically for these post types, which has led to a noticeable increase in views for those posts and announcements.

Before, these posts were harder to discover, but now, with the search functionality, they have become much easier to find, helping more users engage with the content.

In this article, we will show you how to easily create an advanced search form for custom post types in WordPress, step-by-step.

How to create advanced search form in WordPress for custom oost types

Why Create an Advanced Search Form for Custom Post Types?

Custom post types allow you to go beyond posts and pages and make different content types for your website. For example, we use custom post types here at WPBeginner to organize our Deals and Glossary sections.

However, WordPress doesn’t include custom post types in its search results by default. As a result, visitors may miss out on important content, and you will miss out on pageviews.

Thankfully, you can include custom post types in your search results using a WordPress search plugin. You can even go one step further and create an advanced form that searches custom post types only.

For instance, at WPBeginner, we have created custom post type search forms on our Deals and Glossary pages.

An example of a custom search form on the WPBeginner website

Often, this kind of advanced search form will help visitors find what they are looking for faster, which will improve the visitor experience and reduce the bounce rate.

First, you can see our guide on how to make custom post types in WordPress. Then, you can jump into our tutorial on how to create an advanced WordPress search form for custom post types below.

Create a New WordPress Search Algorithm With a WordPress Plugin

The easiest way to create an advanced search form for custom post types is by using the SearchWP plugin. It’s the best search plugin and allows you to search content that WordPress ignores by default.

For example, you can make blog comments searchable and add PDF indexing and searching to your website.

How to Set up SearchWP

The first thing you need to do is install and activate the SearchWP plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you must go to SearchWP » Settings and click on the ‘General’ tab.

Enter SearchWP license key

You now need to enter your license in the ‘License Key’ box. You can find this information in your account on the SearchWP site.

Once you are done, make sure to click the ‘Verify Key’ button.

Creating a Custom Search Algorithm

Your next task is creating a custom search algorithm. It allows you to specify the content that SearchWP includes in its search results, like pages, posts, media, and any custom post types.

To get started, you need to go to SearchWP » Algorithm in your WordPress admin dashboard.

Creating a search algorithm using SearchWP

Here, you will see a section for every content type that SearchWP includes in its search results.

To add your custom post type, just click the ‘Sources & Settings’ button.

How to add custom post types to a WordPress search engine

In the popup that appears, check the box next to each custom post type that you want to include in the search results.

After that, click on ‘Done’.

Creating a WordPress search form for custom post types

SearchWP will add a new section for each custom post type. Each section shows all the attributes that SearchWP will include in its searches, such as the title, slug, and excerpt.

If you want to add or remove attributes, then simply click on ‘Add/Remove Attributes’.

Creating a search form for custom post types

In the popup, check the box next to each attribute you want to include in the search results.

To remove an attribute, you can uncheck its box instead.

Adding attributes to the SearchWP search algorithm

In this popup, you can also make custom fields searchable in WordPress.

When you are happy with the changes you have made, go ahead and click on ‘Done’.

You will notice that each attribute also has an Application Attribute Relevance slider. This controls how SearchWP ranks the content when building its search results page in WordPress.

If an attribute has high relevancy, then it will have a bigger impact on the search results. By contrast, content that matches an attribute that has less relevancy will appear lower in the search results.

For example, if you move the ‘Title’ slider to the right and the ‘Content’ slider to the left, then a post’s title will carry more weight than the content.

Creating a custom search form for your WordPress blog or website

Every WordPress website is unique, so you may want to try different relevancy settings to see what gives you the most accurate and helpful search results.

For example, if you have created a ‘customer reviews’ custom post type for your online store, then this is important content, so you may want to give it a high relevance.

When you are happy with how the search feature is set up, just scroll to the top of the screen and click the ‘Save’ button.

Saving the custom post type search algorithm

SearchWP will now rebuild the index automatically. Depending on the speed of your Internet connection and your WordPress hosting provider, this may take a few minutes.

As soon as you see ‘Index Status 100%’, you will know that SearchWP has added your custom post types to its search index.

Rebuilding the WordPress search index

Your WordPress blog, website, or online marketplace will now include custom post types in its search results.

Create an Advanced Search Form for Custom Post Types

With that done, you are ready to make an advanced form that searches your custom post types only.

To get started, head over to SearchWP » Search Forms and click the ‘Add New’ button.

Creating a new custom search form

This creates a new form, ready for you to customize.

To give this form a unique name, click on the small pencil icon next to ‘Search Form 1’.

Renaming the custom search form using SearchWP

You can now type in a name for the custom search form.

This is just for your reference, so you can use anything that helps you identify the form in your WordPress dashboard. This is particularly important if you plan to create multiple search forms in WordPress.

Creating an advanced search form using SearchWP

After that, you can choose the layout you want to use using the ‘Layout Theme’ thumbnails.

Simply click on the different themes to see a preview of how this style will look on your WordPress website.

Choosing a theme for the custom search form

To create a search form for custom post types, you will typically want to use either ‘Basic’ or ‘Quick Search.’

These styles don’t allow visitors to search by category, which helps to keep them focused on custom post types.

Creating a quick search form for your WordPress website or blog

After making your decision, scroll to the ‘Custom Styling’ section.

The settings you see may vary depending on your theme layout. For example, if you selected ‘Quick Search’, then the ‘Quick Search’ setting will be enabled by default.

Adding custom styling to a search bar in WordPress

You can disable and enable the different options using their toggles.

The live preview will update automatically as you make changes, so you can try different settings to see what works the best.

By default, the form searches media, pages, and posts and ignores custom post types. To include custom post types, you need to find the ‘Type of search’ field and click it.

Searching posts, pages, media, and more using SearchWP

You can now type in the name of each custom post type.

When the right post type appears, give it a click to add it to the search.

Adding custom types to a WordPress search bar or form

Do you want to search for custom post types only and ignore all other content?

Then just click the small ‘X’ next to ‘Media’, ‘Pages’, and ‘Posts’.

Removing post types from a custom search algorithm

With that done, the form will search your custom post types only.

When you are happy with how the form is set up, scroll to the ‘Form Style’ section. Here, you can choose between different form styles, add a border, change the font size, and more.

Changing the WordPress form style

Under ‘Button Style’, you can customize the ‘Search’ button that appears in the form.

When you are happy with how the form is set up, scroll to the top of the screen and click on ‘Save’ to store your settings.

Saving the custom search settings on your website or blog

How to Add the Custom Post Types to WordPress

Now, you are ready to add the search form to WordPress using either a shortcode or block.

The easiest method is to use a block, so head over to the page or post where you want to add the custom post type form.

You can then click on the ‘+’ icon and type in ‘Search Form’.

Adding a search block to your WordPress blog or website

When the right block appears, give it a click.

Next, open the ‘Select a Form’ dropdown menu and choose the search form you made during this tutorial.

Showing a custom search from in WordPress

When you are ready to make the search form live, simply click on either ‘Update’ or ‘Publish’. Now, you can visit your website to see the search form in action.

Another option is to add the search form using a shortcode.

To get the shortcode, you need to head over to SearchWP » Search Forms. Here, find the search form that you want to show and copy the value in the ‘Shortcode’ column.

Getting the shortcode for a custom search form

You can now add the shortcode to any page, post, or widget-ready area. For step-by-step instructions on how to do this, please see our guide on how to add a shortcode in WordPress.

Bonus: Add Custom Post Types to Your RSS Feed

Now that you have created a search form for custom post types, you can also add them to your main RSS feed. This will make it easier for users to discover more content on your website and subscribe to it.

Plus, allowing custom post types in the main RSS feed can boost your site’s SEO.

To do this, you will need to add the following custom code to your functions.php file. keep in mind that it can be a bit dangerous because the smallest can break your website.

function myfeed_request($qv) {
if (isset($qv['feed']))
$qv['post_type'] = get_post_types();
return $qv;
}
add_filter('request', 'myfeed_request');

That is why we recommend using WPCode. It is the best WordPress code snippet plugin and the safest way to add custom code.

Upon plugin activation, just visit the Code Snippets » + Add Snippet page and choose the ‘Add Your Custom Code (New Snippet)’ option.

addnewsnippet

This will direct you to the ‘Create Custom Snippet’ page, where you must add a snippet name and choose ‘PHP Snippet’ as the code type.

After that, you can add the code and toggle the ‘Inactive’ switch to ‘Active’.

Save Snippet for adding custom post type to WordPress RSS feed

Then, click the ‘Save Snippet’ button to store your settings. Your custom post types have now been added to the main WordPress RSS feed.

For details, see our tutorial on how to add custom post types to your main WordPress RSS feed.

We hope this article helped you learn how to create an advanced search form in WordPress for custom post types. You may also want to see our tutorial on how to use multiple search forms in WordPress and our guide on how to exclude specific pages, authors, and more from WordPress search.

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. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

36 CommentsLeave a Reply

  1. Jiří Vaněk

    I tried to set up Advanced Custom Fields and custom post types for reviews on my website so that everything is personalized and has its own structure. It was only thanks to this article that I learned there might be a problem with searching content for custom post types. This is new information for me. Since Search WP caught my attention in many of your other articles, it’s evidently a very handy search tool that I definitely want to try. After all, it can also solve many other search-related issues discussed here. Thanks for the great tip.

  2. tinhbeng

    Hi,
    How to me can add product post type in here?

    Thank,

  3. vijay

    Thanks for the information, I want to know whether there is any way I can have dropdown style of search forms, as I have large number of post types, it would make it look ugly if I put all of them below search bar.

  4. Penguin

    Hi, Thanks a lot. This works pretty good for me. I am using dropdown instead of checkbox. But how can I style it to make it smilar to the one in LinkedIn header search section? Does that requires javascript? Do I use font icons for that? I am using fontawesome in my header. But I don’t know how to integrate this with fontawesome in a dropdown.

  5. mayur

    Sir.. can you plz attach screenshot with tutorials afterwords?? i think it’s more helpful for us..

  6. Sean

    Check out WP Advanced Search: http://wpadvancedsearch.com/

    We’ve got support for taxonomies, custom fields, and just about everything else that WP_Query supports.

  7. Brad

    How could I use this to search a custom table of data. This is for a sports team site, and basically, I need a search box where someone can “Search by”: Last name, First name, or Team.

    So how can I search by a field name?

  8. Darren

    This is an awesome tutorial, thank you.

    Is there a way that I could mix this with categories? So that I could have both custom post types and categories selectable?

    Thanks again :).

  9. ONEEEZY

    Dang.. still nothing. . .

  10. Marie

    Hi, there isn’t a way to tell the engine to automatically list all terms or tags or custom field? thanks

  11. Elliott

    Nice tutorial… Am designing a custom search for my new site at the moment.

    Curious why you don’t think searching on pages is a good idea?

    • Editorial Staff

      You can search pages except in most cases your about page, contact page, legal page, privacy policy page are mostly irrelevant.

      Admin

  12. Fakeuser

    I’m getting this error after changing the name of the input fields to s[]

    Warning: stripslashes() expects parameter 1 to be string, array given in wp-includes\query.php on line 2179

    I’ve changed the call to stripslashes() call to stripslashes_deep() but it broke other thigs… any sugestions?

  13. Benjamin Wilde

    I’m looking for a way to have a form with separate controls for location AND category, both in dropdown boxes. Obviously I can do this, but I have no idea how to do a multiple-query search in Wordpress. Any ideas?

  14. Aldo Valverde

    Do you think is it possible to do the same but including Post Type Categories as well….

    …I mean, the same Post Type checkboxes and when user select an specific checkbox that appear-down other checkboxes but as categories and filter even more the Search of Wordpress ?

  15. Rocky Ouprasith

    Awesome! thanks for the help!
    there is one thing though…

    my post types are all styled differently.
    how can I assign the template of a post type with the correct post types?

    thanks!

    • Editorial Staff

      Use CSS classes. Each post outputs its own post classes i.e categories, post types etc.

      Admin

  16. SDesign

    Great tutorial! One question though: What would the syntax be for making the checkboxes in the form use taxonomies rather than post types?

    Would something like this work?:

    Perhaps this is worthy of another tutorial. Any additional help is greatly appreciated.

    • Thad

      Ever come across anything that explains this?

      • SDESIGN

        No, I decided to go with custom post types instead.

        If anyone has any insight, on this it would be greatly appreciated.

        The specific question is how to make something like this work using taxonomies instead of post types?

  17. CathieHeart

    Hi, you wouldn’t happen to also have a section to add maybe for those of us wanting to a dropdown menu search form interface rather than checkboxes? 
    Thanks.

    • wpbeginner

       @CathieHeart That can be accomplished using the similar technique.

  18. mainaPlus

    Does this work with a buddypress enabled site?

    • wpbeginner

       @mainaPlus Haven’t tried it with BuddyPress so not sure

  19. Robin

    Would this be able to work with a buddypress enabled site?

  20. Herny Louis

    Thanks Syed and David. Need to test it on one of my websites. Definitely this kind of categorization will help visitors to do narrow search.

  21. zachshallbetter1

    I would love to see a way to do this with custom fields as well.

    • oneeezy

      Yes!
      What Zach said…

      It would be ideal to have this “Advanced Form” be able to search through custom fields. You could make the ultimate search form this way. Any takers??? C’mon WP Beginner!!

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.