105

Do you want to create an 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.

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

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.

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.

Activating the SearchWP search plugin

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.

Adding custom post types to 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 will search media, pages, and posts and ignore custom post types. To include custom post types, you need to find the ‘Type of search’ field and give it a click.

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 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.

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 custom post types tutorials and our expert picks for the best WordPress plugins to grow your website.

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.

The post How to Create Advanced Search Form in WordPress for Custom Post Types first appeared on WPBeginner.

Want to receive personalized offers?

Allow notifications to get real-time updates about your shopping cart and who knows, you may even receive a sweet discount code 😊

Maybe later