How Does WordPress Search Work (+ Tips to Make It Better)

Do you want to learn how WordPress search works, and how you can make it better?

By understanding and improving the built-in WordPress search, you can help visitors find what they’re looking for. This can get you more conversions while keeping people on your site for longer.

In this article, we’ll look at how the default WordPress search works, and share tips on how to make it better.

How does WordPress search work + tips to make It better

How Does WordPress Search Work?

WordPress comes with a search system that will look for content within your website.

How the search bar looks and where it appears will vary depending on your WordPress theme, but most themes show the search bar in the top right corner.

The built-in WordPress search bar

Note: If your theme doesn’t show the WordPress search bar by default, then skip ahead to our FAQs, where we’ll show you how to add it.

Visitors can type a search query into this field, and WordPress will search:

  • Page titles
  • Page content
  • Single-image titles and captions
  • Image alt text
  • File names

As you can see, it doesn’t search widgets, user comments, categories, tags, WooCommerce products, or PDF documents. It also doesn’t search image gallery titles, captions, or alt text, although you can search this content using a search engine plugin like SearchWP.

WordPress performs this search using the WP_Query class. It will start by displaying any posts that have the search term in the post title, arranged in reverse-chronological order, meaning that the newest entries will be displayed at the top of the results.

After that, it’ll show any posts that have the matching term in the post content.

For example, imagine you’ve just published a post about cats titled ‘My Favorite Pet’, and you also have an older post titled ‘Best Cat Photos.’ In this case, searching for ‘Cat’ will display the older ‘Best Cat Photos’ post first, since it has the search term in the title.

This may not a problem for WordPress blogs or websites that only have small amounts of content. However, this ordering logic will often show inaccurate or confusing results for bigger blogs, online stores, or business websites.

The built-in system is also missing some of the features that people expect from modern search engines. This includes autocomplete, live Ajax search, filtering, and spellcheck.

Why Improve the Default WordPress Search?

An advanced, fast, and accurate on-site search can help visitors find interesting and relevant content, which will keep them on your website for longer. This can increase pageviews and reduce bounce rate in WordPress.

Since visitors are spending more time on your site, this will send positive signals to the search engines. This can improve your WordPress SEO, which means search engines like Google will show your content to more people and drive more visitors to your website.

For more information, please see our guide on how to increase your blog traffic.

People who are using your site’s internal search are already highly engaged. They’re actively looking for specific content, which may mean they’re ready to take actions such as buying a product, signing up to your WordPress membership site, or booking an appointment.

If these people can’t find what they’re looking for, they may give up and go to a different website. This means you’re losing out on visitors who were ready to convert.

A search results page is also an example of personalized content since you’re showing the visitor results that match their unique search query. By providing personalized content that’s accurate and helpful, you can improve the visitor experience. Once again, this can encourage them to convert.

Performance is another reason why it’s a good idea to replace the default WordPress search with a better alternative.

The larger your WordPress website gets, the longer it’ll take WP_Query to scan your database and get the results. This means your site’s search will get slower, as your website gets bigger.

How to Make the WordPress Native Search Better

On-site search helps visitors find what they’re looking for, including products to buy and interesting blogs to read. Since it’s such an important part of your site, it’s a bad idea to rely on the limited built-in WordPress search.

With that being said, let’s see how you can improve the native WordPress search.

Show Instant Results With Live Ajax Search

Live Ajax search adds a dropdown and autocomplete feature that’s common in search engines like Google.

As the user types, live search guesses what they want to search for and then shows them results without even reloading the page.

How to improve WordPress search with live ajax results

This can help visitors find the right content, without having to manually press the ‘Search’ button or wait for the page to reload.

The easiest way to add Ajax live search to WordPress is using the free SearchWP Live Ajax Lite Search plugin. It enables instant search automatically and there are no settings for you to configure, so it’s very easy to set up.

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

Upon activation, the default WordPress search form will automatically use the Ajax live search feature. If you visit your site and start typing into the search bar, then you’ll see the instant search in action.

Change the Default Search URL Slug

By default, WordPress search URLs typically look something like this:

http://example.com/?s=search-term

The extra ?s= characters make this URL more difficult to read and understand, which can confuse visitors who are trying to find their way around your site.

Even worse, these URLs aren’t optimized for search engines which can stop them from correctly indexing your site’s contents.

The easiest way to change these URLs is by adding custom code to WordPress using a plugin such as WPCode.

You can go ahead and use the following custom code to replace the ‘/?s=search-term’ characters with ‘search.’ Your slug will look something like this when finished: http://example.com/search/wordpress

To use something other than ‘search’ in your URL, simply customize the code snippet below.

function wpb_change_search_url() {
    if ( is_search() && ! empty( $_GET['s'] ) ) {
        wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
        exit();
    }
}
add_action( 'template_redirect', 'wpb_change_search_url' );

For detailed instructions on how to insert this code to your WordPress website, please see our guide on how to change the default search URL slug in WordPress.

Make PDF Files Searchable in WordPress

By uploading PDFs to your WordPress website, you can share information about your services and products in a format that works on all devices. They’re also perfect for offering your visitors ebooks, user manuals, menus, and more.

However, WordPress only searches the contents of its database by default, so it will only look at the title and description of your PDF files, and not their contents. As a result, your visitors may struggle to find the best PDF for their search query.

The good news is that you can use a custom search plugin to improve the default WordPress search experience. If your PDFs are unencrypted, then the right search plugin will index the contents and metadata of your PDFs and add them to the search results.

For step-by-step instructions, please see our guide on how to add PDF indexing and searching in WordPress.

Add a Search By Category Feature to WordPress

If you have multiple categories of content on your website, then you might want to let users restrict their search to a specific category. This can help visitors find the right content, faster.

An example of search by category on a WordPress website

For example, if you have an online store then it often makes sense to let customers search within a particular product category.

If you run a membership site, then you might use search by category to help visitors find other members, groups, forums, online courses, and other specific kinds of content. For more information, please see our guide on how to add search by category in WordPress.

Make a Smart WooCommerce Product Search

WooCommerce has its own built-in search, but it doesn’t look for matches in product attributes, reviews, or product descriptions. This omission can stop shoppers from finding products they want to buy on your online store, so you get fewer sales.

The built-in WooCommerce search feature

Luckily, there are some excellent WooCommerce plugins that can show more helpful search results, and fetch them faster. To learn more, please see our guide on how to make a smart WooCommerce product search.

To get even more sales, you may want to fine-tune the kind of products WooCommerce includes in its search results. For example, you might only show products that are on sale or come with free shipping.

To learn more, please see our guide on how to customize WooCommerce product search results page.

Create a Search Form for Custom Post Types

Custom post types allow you to go beyond posts and pages and create different content types for your website. Custom post types can have different custom fields and their own custom category structure.

For example, if you run a movie review website, then you would probably want to create a ‘movie reviews’ post type that has fields for the director, release date, and more.

At WPBeginner, we use custom post types for our Glossary section to keep it separate from our blog posts.

How to improve your WordPress search with searchable categories

If you use custom post types, then you may want to create a form that allows visitors to search only that content.

For example, we also have a form that only searches WPBeginner’s coupon codes.

Searching coupons and deals on the WPBeginner website

This can help visitors find the right content faster, even when you have lots of different content types. For step-by-step instructions, check out our guide on how to create advanced search forms in WordPress for custom post types.

You can also make custom fields searchable in WordPress, which is ideal if you’ve added extra metadata to your pages and posts.

Exclude Content From WordPress search

By default, the built-in WordPress search will include all posts and pages in its search results.

However, you may want to exclude certain pages and posts from the search results. For example, if you’re running a WordPress membership website or selling online courses, then you’ll typically want to exclude your premium content from public search results.

If you’re running an online store, then you may want to hide content like your account page, checkout page, and thank you page. To help you out, we’ve created a guide on how to exclude pages from the WordPress search results.

Do you want to exclude posts, authors, custom post types, categories, tags, or even custom taxonomies? Then you can take a look at our guide on how to exclude specific pages, authors, and more from WordPress search.

WordPress Search FAQs

In this guide, we’ve explored how the default WordPress search works and shared lots of tips on how to improve it.

However, you may still have some questions about this important feature. That said, here are some of the most frequently asked questions about WordPress search.

How Do I Improve WordPress Search?

The best way to improve the built-in WordPress search is by using SearchWP.

SearchWP is the best custom search plugin for WordPress and allows visitors to search any content on your site including documents, WooCommerce products, custom fields, tags, comments, and more.

It also lets you customize the WordPress search algorithm, so you can control exactly where the content appears in the search results.

For more information, please see our guide on how to improve WordPress search.

Does WordPress Search Include Tags?

By default, WordPress search doesn’t include tags. The easiest way to make tags searchable is by using a custom search plugin like SearchWP.

SearchWP also has a relevancy slider, so you can control exactly how much tags influence where an item appears in the search results.

How Do I Add Search to My WordPress Theme?

If your theme doesn’t have a built-in search form, then we recommend adding a search bar to the WordPress navigation menu.

Since the main navigation menu typically appears across your entire site, visitors will be able to search for pages, posts, products, and more, from any page of your website.

An example of a search bar, in a navigation menu

If you’re using a block-based theme such as ThemeIsle’s Hestia Pro or Twenty Twenty-Three, then you can add a search bar to your theme using the full-site editor (FSE).

To do this, go to Appearance » Editor in the WordPress dashboard.

Opening the WordPress full site editor (FSE)

By default, the editor will show your theme’s home template. If you want to add the search bar to a different template, then click on the small arrow icon in the toolbar.

Then, select ‘Browse all templates.’

How to browse all FSE templates in WordPress

You’ll now see all the templates that make up your WordPress theme. Simply find the template where you want to add the search bar, and then click on its title.

For example, if you wanted to add a search form in your WordPress posts then you’d select the ‘Single’ template.

How to add the search bar to a single template in WordPress

You will now see this template in the full-site editor.

To go ahead and add a search bar, click on the blue ‘+’ icon.

Adding widgets to a single template in WordPress

In the popup that appears, type in ‘Search’ to find the right block.

You can then drag the block to the location where you want to show the search bar.

Adding a search block to a block-enabled theme template

To customize the block title or placeholder text, simply type it into the search block where it says ‘search’ or ‘optional placeholder.’

When you’re happy with how the block looks, click on ‘Save’ to make the search bar live.

Publishing a block-enabled template with a search bar

How Do I Add Search to a WordPress Page or Post?

You can add a search bar to a specific page or post using the built-in Search block.

This is a good choice if you want to control exactly where the search bar appears on every page and post, or you only need to offer search on specific areas of your website.

How to improve the default WordPress search

To get started, simply open the page where you want to add a search form and then click on the + icon.

In the popup that appears, type ‘Search’ to find the right block. Once you click on the Search block, it will add the block to your page.

Adding the Search block to a WordPress page or post

By default, the block uses ‘Search’ for both its label and the button text.

This will be visible to visitors, so you may want to replace it with something more descriptive by typing into the text fields.

Customizing the WordPress search block

You can also add some placeholder text to the search bar. This text will disappear automatically when the visitor starts typing.

To add a placeholder, simply click on ‘Optional placeholder…’ and then start typing.

How to improve the WordPress search

When you’re happy with how the Search block looks, you can go ahead and either publish or update the post.

We hope this tutorial helped you learn how WordPress search works, and how to make it better. You may also want to learn how to make money online blogging with WordPress, or check out our list of the best email marketing services for small businesses.

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 Does WordPress Search Work (+ Tips to Make It Better) first appeared on WPBeginner.

How to Create a Custom WordPress Search Form (Step by Step)

Do you want to create a custom search form for your WordPress website?

Search is how most users find relevant and interesting content on your site. If they can’t easily find what they’re looking for, then they may move on to a different website.

In this article, we’ll show you how to improve your website search by creating a custom WordPress search form.

How to create a custom WordPress search form (step by step)

Why Create a Custom Search Form for WordPress?

WordPress comes with a built-in search feature. However, it doesn’t search all types of content such as comments, product reviews, or custom post types.

This may stop the visitor from finding what they’re looking for, including products they may want to buy on your online store.

You may also want to prioritize some content over others, so that it appears higher in the search results. For example, you may want to show your site’s latest posts at the top of the search results page, or display your most popular WooCommerce products.

With that in mind, let’s see how you can customize the WordPress search form. We cover a lot of ground in this post, so simply use the quick links below to jump straight to the section you want to read.

How to Customize the WordPress Search Alogrithm

The easiest way to improve the built-in WordPress search algorithm is by using SearchWP.

SearchWP is the best WordPress search plugin. It’s easy to use and gives you complete control over your site’s search algorithm, so you can help visitors find what they’re looking for, fast. It also searches content that WordPress ignores by default.

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

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

How to activate the SearchWP search plugin

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

Once you’re done, click the ‘Verify Key’ button.

Customizing the Search Engine

After activating the plugin, you can fine-tune how SearchWP indexes, searches, and displays your content. You can think of this as creating a custom Google search algorithm that’s just for your WordPress blog or website.

To start, head over to SearchWP » Algorithm.

Creating a custom search algorithm for your WordPress website

Here, you’ll see a section for the different content types that SearchWP searches by default, including pages, posts, and media files.

To include more content types in the search results, click on the ‘Sources & Settings’ button.

How to search additional content types using SearchWP

You’ll now see a popup with all the different content types SearchWP can search. For example, you can make blog comments searchable in WordPress.

Depending on the WordPress plugins you’ve installed, you may see some extra options. For example, if you’re using WooCommerce then you can include ‘Products’ in the SearchWP search results.

For more on this topic, see our guide on how to make a smart WooCommerce product search.

Simply go ahead and check the box next to each content type you want to include in the search results.

Adding additional content types to WordPress search

You’ll also notice that ‘Keyword Stems’ is selected by default. This means SearchWP may include results that don’t have the same ending as the search term.

For example, if you search for ‘run’ then keyword stemming will include ‘running,’ and ‘runners’ in the results.

This can help show relevant results to visitors, so we recommend leaving the ‘Keyword Stems box checked. However, you can uncheck it if you want to show exact matches only.

SearchWP's keyword stems feature

When you’re happy with the information you’ve entered into the popup, click on ‘Done.’

You’ll now see a section for all the sources you selected.

Searching products and comments on a WordPress store

Each section has its own ‘Applicable Attribute Relevance’ sliders.

This is the weight that SearchWP will give to each attribute when creating the search results.

Creating a custom search algorithm using SearchWP

Content that matches an attribute with high relevancy will appear higher in the search results. By contrast, content that matches an attribute that has less relevancy will appear lower in the user’s search results.

To give an attribute greater weight, simply move its slider to the right. In the following image, the search engine will place more value on matches that it finds in the post title, compared to matches that it finds in the post’s content.

Customizing the applicable attributes relevance slider

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’ve uploaded your menu as a PDF on your restaurant website, then this is important content and you’ll typically want to show it high in the search results.

You can also create rules that determine whether certain content is included or excluded from the search results. For example, if you have an online marketplace then you may want to exclude the account page, checkout page, and thank you page.

Simply click the ‘Edit Rules’ button in the section where you want to create the rule. For example, in the following image, we’re adding a new rule to the ‘Posts’ section.

Adding rules to your search engine

This opens a popup where you can edit the search engine rules.

To go ahead and create your first rule, click on the ‘Add Rule’ button.

Editing the rules for your website's search

You can now choose the content you want to include or exclude from relevant search results.

To start, open the first dropdown menu and choose either ‘Only show entries if’ or ‘Exclude entries if’ depending on the kind of rule you want to create.

Adding a custom rule to your search form

You can now use the rest of the settings to specify the content you want to exclude or include. For example, if you wanted to include or exclude a specific category then you’d type in the category name.

You can also type in any custom taxonomies you want to exclude or include.

Excluding categories form the WordPress search results

To exclude or include specific post tags from the search results, simply open the dropdown menu and select ‘Tags.’

Then, type in the tag’s name.

Excluding tags from the WordPress search results

To add another rule, just click the ‘Add Rule’ button and repeat the same process described above. When you’re happy with how the rules are set up, click ‘Done.’

You can now create rules for other content types such as media and pages, by scrolling to their sections and clicking on their ‘Add Rule’ buttons.

When you’re happy with how the search algorithm is set up, scroll to the top of the page and click on ‘Save.’

Saving a custom search algorithm on your WordPress website

SearchWP will now rebuild the index. 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’ll know that SearchWP has added all your content and rules to the search index.

Rebuilding the WordPress search index

Create Custom Search Forms For Your WordPress Website

By default, all the search forms on your WordPress website will use the new SearchWP algorithm you created in the previous section. This means that visitors will start seeing more accurate and relevant results straight away.

However, for even better results you may want to create advanced search forms for different kinds of content. For example, you might create a smart WooCommerce product search form that looks at particular product categories only.

You can also create an advanced search form for custom post types. For example, we’ve created a custom post type search form for our Deals and Glossary pages.

An example of a custom search form on a WordPress website

Each form will override the default WordPress search algorithm, so you can create as many different forms as you want with unique settings.

How to Create a Custom Search Form

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

Adding a custom search form to your WordPress website

This creates a new search form, ready for you to customize. For example, if you run a review website, then you might create a form that searches for product review posts and ignores other content like your blog posts and media. This can help visitors find what they’re looking for, faster.

Now, give the form a unique name by clicking on the small pencil icon next to ‘Search Form 1’.

How to create an advanced search form using SearchWP

You 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 the WordPress dashboard.

Adding a title to a custom search form

After that, you can choose a layout using the ‘Layout Theme’ thumbnails.

Some of these layouts are designed for specific search forms. For example, if you are creating a form that searches by category in WordPress, then ‘Category Search’ already has many of the settings you need.

Choosing a theme for your WordPress search form

Simply click on the different themes to see a preview of how this form will look on your website. 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.

Choosing a search form theme

You can disable and enable the different options using their toggles. The preview will update automatically as you make changes, so you can see what works best for your website.

Depending on your layout and the kind of form you want to create, you may need to enable and disable some of the ‘Custom Styling’ settings. For example, if you want to create a form that searches by category, then click to enable the ‘Category Search’ toggle.

After that, find the ‘Select Category’ field and type in each category that you want to include in the search results. For example, if you run an online store, then you may want to create forms that search specific product categories.

Customizing the WordPress search form

If you want to allow visitors to filter their search results using factors like the author, post type, and tag, then you will need to click to enable the ‘Advanced Search’ toggle.

After that, scroll to the ‘Advanced Search Filter/s’ field. By default, SearchWP allows visitors to filter their results using Authors, Post Types, and Tags.

Changing the WordPress search filters

To remove any of these filters, just click on its ‘X’ button. If you want to add more filters, then simply type their names into the field.

Then, when the right option appears in the dropdown, give it a click.

Searching WordPress tags using SearchWP

By default, SearchWP will search all the media, pages, and posts on your WordPress website. If you’ve created any custom post types, then you can include them in the search results using the ‘Type of search’ field.

Simply go ahead and type in each custom post type that you want to include. When the right custom post type appears, click to add it to the search.

How to search custom post types in WordPress

Do you want to exclude media, pages, or posts from the search results?

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

Creating an advanced search form in WordPress

By default, SearchWP will show a generic ‘Enter keyword and search’ message before the visitor enters a search query.

You can replace this with your own messaging by typing into ‘Field Label’.

Change how the custom search form looks on your website

When you are happy with these settings, scroll to the ‘Form Style’ section.

Here, you can choose between different form styles, add a border, and change the font size.

Choosing a new form style using SearchWP

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

There are more settings that you can use to change how the form looks and acts. However, this is all you need to create an advanced custom search form.

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

How to save your custom form settings

To create more custom search forms with unique settings, simply repeat the exact same process described above.

Add a Custom Search Form to Any Page, Post, or Widget-Ready Area

You can add an advanced search form to any page, post, or widget-ready area using the Search Form block.

As an example, let’s see how you can add a search form to a post. Simply open the post in the WordPress content editor and click on the ‘+’ icon. Then, type in ‘Search Form’.

Adding a search form to any WordPress page or post

When the right block appears, give it a click.

You can now open the ‘Select a Form’ dropdown and choose the form you want to use.

Choosing between multiple search forms in WordPress

When you are ready to make the search form live, just click on either ‘Update’ or ‘Publish’. Now, simply visit this page or post to see the search form in action.

To add a search form to a widget-ready area, head over to Appearance » Widgets. Here, click the ‘+’ block icon in the area where you want to show the search form.

Adding a search block to any widget-ready area

Then, type in ‘Search Form’.

When the right block appears, click to add it to the widget-ready area.

Adding a search form to the sidebar or similar section

You can now open the dropdown menu and choose the search form that you want to use.

When you are finished, just click the ‘Update’ button to make the search form live.

Publishing a search bar in WordPress

For more detailed instructions, please see our guide on how to add and use widgets.

Adding Live Ajax Search to a Custom Search Form

Many online marketplaces and websites use live Ajax search. This automatically shows possible search results as the user types in the custom form, similar to how search engines such as Google work.

An example of a live Ajax search on a WooCommerce online store

With Ajax live search, you can show relevant results without even reloading the page. This makes it a great choice if you sell digital downloads or physical products online, as shoppers can instantly see products that match their search query.

The easiest way to add Ajax live search to WordPress is by using SearchWP Live Ajax Lite Search. This free plugin automatically adds instant search to your website and works perfectly with any WordPress theme.

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

Upon activation, the default WordPress search form will automatically use the Ajax live search feature. If you visit your site and start typing into the search bar, then you’ll see instant search in action.

For more detailed instructions, please see our guide on how to add live Ajax search to your WordPress site.

Using Advanced Settings for SearchWP

Next, it’s a good idea to enable some advanced settings that will make it easier for users to find what they’re looking for.

To do this, go to SearchWP » Settings and scroll to the ‘General Settings’ section.

SearchWP's advanced search settings

Here, you can activate any of the following settings:

  • Partial matches. With this setting enabled, SearchWP will display results that aren’t an exact match for the visitor’s search query.
  • Closest match. After enabling partial matches, you can also show the closest matches when a search has no results.
  • “Quoted” searches. This allows visitors to search for exact phrases using quotes.
  • Highlight terms. Automatically highlights the search terms to help visitors find what they’re looking for.

Measuring Search Results and Improving Conversions

To help you fine-tune your website’s search, it’s a good idea to monitor how visitors are using the search feature. This allows you to see what’s working and what’s not working on your WordPress blog, so you can constantly improve your site’s search and help visitors find what they are looking for.

This data can even help you generate blog post ideas by showing the content that visitors are already searching for.

To see the search history and most popular search terms, simply select ‘Statistics’ in the left-hand menu.

SearchWP's advanced search settings

We hope this tutorial helped you learn how to create a custom WordPress search form. You may also want to see our picks of the best live chat software for small businesses and our guide on how to get a free business email address.

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 a Custom WordPress Search Form (Step by Step) first appeared on WPBeginner.