
Search a WordPress site for “cache plugin” and the first result can be a 2016 note that mentions both words once, sitting above the 3,000-word guide actually titled “Cache Plugins for WordPress”. The guide is on page two.
That is not a relevance bug. WordPress built in search asks the database one question: does this post contain these words anywhere in the title, excerpt, or content? It does not read intent, it does not look at custom fields, and it does not know that a reader who types “cahce” meant something.
The good news is that the query is inspectable. Most of what follows comes from WP_Query, and most of it can be changed with a filter rather than a plugin.
What the built-in search actually queries
Strip the query down and the WHERE clause looks like this. Each term gets its own group of three LIKE checks, and the groups are joined with AND:
-- Simplified shape of the search clause core builds for "cache plugin".
AND (
( wp_posts.post_title LIKE '%cache%'
OR wp_posts.post_excerpt LIKE '%cache%'
OR wp_posts.post_content LIKE '%cache%' )
AND
( wp_posts.post_title LIKE '%plugin%'
OR wp_posts.post_excerpt LIKE '%plugin%'
OR wp_posts.post_content LIKE '%plugin%' )
)
Three details follow from that shape.
Every term must match. The AND between groups means a post about caching that never uses the word “plugin” is excluded, even if it answers the question. Searching “how to speed up WordPress” is worse: how and to are dropped as stopwords, so the query becomes speed AND up AND wordpress, and a post titled “WordPress Speed Optimization” fails because it never says “up”.
The match is a substring, not a word. LIKE '%cache%' finds “cache”, “cached”, and “caching” inside a sentence. It also finds “cache” inside a longer word. The reverse does not work: searching “caching” will not match a post that only says “cache”.
Only three columns are searched. Title, excerpt, and content. Not post meta, not taxonomy terms, not comments, not product SKUs. The WP_Query search parameters list the full set, including sentence for an exact phrase.
| Data | Searched by default | Why it matters |
|---|---|---|
| Post title | Yes | Highest weight in the ranking |
| Excerpt and content | Yes | Broad but noisy |
| Custom fields | No | SKUs, addresses, prices are invisible |
| Categories and tags | No | A tag name alone will not surface a post |
| Comments | No | Reader discussion is not indexed |
| Attachments | No | Media titles do not appear in results |
Term parsing adds more rules. Quoted input is kept as a phrase. A search with more than nine terms is matched as one sentence instead of individual words. Single letters and a fixed stopword list are discarded. That list is filterable through wp_search_stopwords, which is useful on a site where a common word is also a product name.
How core orders the results
WordPress has ranked search results since version 3.7, and the ranking is simpler than most people assume. When a search has more than one term, core sorts with a CASE expression with six tiers:
- The exact phrase appears in the title.
- All terms appear in the title.
- Any term appears in the title.
- The exact phrase appears in the excerpt.
- The exact phrase appears in the content.
- Everything else.
Within a tier, the default date order applies, newest first. A single-term search skips the case statement and puts title matches first, then sorts by date.
The practical consequence: a two-line note whose title is “Cache Plugin” beats a long guide that contains the phrase in its body. Core is rewarding the title, not the depth. If your search results look arbitrary, the query is doing exactly what it was written to do.
There is one escape hatch in core. If a query sets any orderby other than relevance, relevance is skipped entirely. That is why some themes and plugins return search results in plain date order without anyone intending it.
Three failures you can reproduce
Too broad. Search “WordPress” on a WordPress blog and every post matches, because every post says “WordPress”. The result is an archive sorted by date, not a search result. Core has no notion of a term being too common to be useful, apart from the short stopword list.
Too narrow. The AND logic punishes natural language. A reader types “fix slow checkout WooCommerce”, and a post titled “WooCommerce Checkout Performance” drops out because it never uses the word “fix”. Adding a term to a search can only remove results, never add them.
Typo intolerant. There is no fuzzy matching and no spell correction. “Cahce” returns nothing. Some plugins add a “did you mean” layer, but the core query has no concept of edit distance.
All three come from the same design: WordPress built in search treats every term as a filter, not as a signal of intent.
A fourth problem is structural: search is limited to the three post columns, so a store that wants customers to find a product by SKU, or a directory that wants to find a listing by city, is searching the wrong table entirely.
Search pages are noindex by design
Core adds noindex, follow to every search page through the wp_robots_noindex_search() function, which hooks into the robots API introduced in WordPress 5.7. The reason is straightforward: search URLs are infinite. Every combination of terms creates a new page, most of them thin, many of them duplicates of category archives, and some of them embarrassing when a visitor searches for a competitor’s name.
Confirm it on your own site before changing anything. With SITE set to your domain, without a trailing slash:
curl -s "$SITE/?s=cache" | grep -i robots
You should see a noindex directive in the output. If you see nothing, a theme or plugin has replaced the standard wp_head output, and that is worth fixing on its own.
Do not remove the noindex to “get more pages indexed”. Internal search pages do not earn rankings; they consume crawl budget and split signals away from the posts that do. The work of improving rankings is a separate discipline, covered in the WordPress search rankings guide. Site search improves the experience of the visitor already on the page. Those are different jobs with different metrics.
Fix the query before the template
Most “WordPress search is broken” complaints are query scope problems. These three changes address the common cases without a plugin.
Scope the search to the post types people mean
A site with products, documentation, and a blog rarely wants one search box to return all three mixed together. Restrict the main query and set a sane page size:
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$query->set( 'post_type', array( 'post', 'page' ) );
$query->set( 'posts_per_page', 20 );
} );
The is_main_query() guard matters. Without it, every secondary query on the page inherits the restriction, including related-posts modules and menu queries. The pre_get_posts documentation covers the other conditionals worth checking.
If you add a custom post type slug to that array, confirm it is public and does not set exclude_from_search => true. A post type can be visible in the admin and still be invisible to search.
Search fewer columns when precision matters
Since WordPress 6.2, WP_Query accepts a search_columns argument limited to post_title, post_excerpt, and post_content. Restricting it to the title and excerpt turns the search box into a headline finder: fewer results, much faster queries, and no matches buried in code samples or footnotes.
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$query->set( 'search_columns', array( 'post_title', 'post_excerpt' ) );
} );
The post_search_columns filter does the same job globally, which is useful when several queries need the same rule. Choose one approach; a filter and a query argument that disagree produce confusing results.
A title-and-excerpt search is a good fit for a documentation index with short, descriptive titles. It is a poor fit for a blog where readers search for a phrase they remember from the body.
Reject the empty search
An empty ?s= is still a search as far as WordPress is concerned. The query runs with an empty term, every LIKE '%%' matches, and the site returns its entire archive with a 200 status, a search heading, and pagination. It is noindexed, but it is crawlable and wasteful.
add_action( 'template_redirect', function () {
if ( is_search() && '' === trim( get_search_query( false ) ) ) {
wp_safe_redirect( home_url( '/' ), 302 );
exit;
}
} );
A 302 is deliberate. The redirect is a convenience for a malformed request, not a permanent rule about the URL. If a form submits with an empty field, the visitor lands on the homepage instead of a wall of unrelated posts.
Custom fields are not in the index
Core will never find a product by SKU, a property by address, or an event by venue, because those values live in wp_postmeta and the search clause never joins that table. Extending it is possible through the posts_search filter, which receives the SQL fragment and the query object.
Two warnings before you write that filter.
First, the fragment you receive is a chain of AND groups. Appending OR EXISTS (...) to the end without wrapping it changes the logic of the whole clause: status = 'publish' AND (title matches) OR (meta matches) will return drafts if a meta row matches. Any addition has to be grouped inside the existing parentheses.
Second, a LIKE '%term%' against wp_postmeta is the slowest version of this query. On a store with 200,000 meta rows, it turns every search into two table scans. If search by custom field is a core feature of the site, a dedicated index is the better architecture than a filter bolted onto core.
The performance ceiling: a leading wildcard
LIKE '%cache%' starts with a wildcard, so MySQL cannot use the index on post_title or post_content. Every search scans the posts table. On a 500-post blog that is invisible. On a 100,000-post archive with long content, it is the slowest query on the site, and it runs on every keystroke if the theme added live search.
The options, in order of effort:
- Search fewer columns. The
search_columnschange above can cut the scanned data by more than half. - Reject empty and one-character searches. Neither returns anything useful, and both cost a full scan.
- Add a FULLTEXT index. InnoDB supports full-text indexes on
post_titleandpost_content, and a MariaDB full-text index changes the query from a scan to an index lookup. It requires a plugin or custom code that rewrites the search SQL; theposts_searchfilter is the entry point. - Move search to an external index. ElasticPress, Algolia, and Typesense handle relevance, typo tolerance, and faceting that core was never designed for. A vector search stack is the next step when semantic matches matter more than exact words.
Page caching does not help here. A cached search result is only useful if the same phrase is requested again, and most are not. The cache plugin guide explains what those plugins cache; search queries are usually not on the list.
If searches feel slow but the rest of the site is fine, measure before rewriting. Query Monitor shows the search SQL and its duration, and the measured speed walkthrough shows how to attribute a slow page to the query that caused it.
Make the results page answer the query
The template is where a mediocre search becomes usable. Three changes do most of the work.
State the query and the count. A reader who searched for “cache plugin” should see that phrase and how many results it produced, not a generic “Search Results” heading. Both values are already in the main query:
<?php if ( have_posts() ) : ?>
<p class="search-summary">
<?php
printf(
esc_html( _n( '%1$s result for “%2$s”', '%1$s results for “%2$s”', (int) $wp_query->found_posts, 'textdomain' ) ),
esc_html( number_format_i18n( (int) $wp_query->found_posts ) ),
esc_html( get_search_query() )
);
?>
</p>
<?php endif; ?>
Give the empty state somewhere to go. When nothing matches, list the top three categories, link the most-read guides, and repeat the search form. A dead end with “No results found” is the moment a visitor leaves.
Use the accessible form. get_search_form() renders the theme’s searchform.php or a core fallback, and accepts an aria_label argument. A minimal template file:
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="site-search"><?php esc_html_e( 'Search this site', 'textdomain' ); ?></label>
<input type="search" id="site-search" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" />
<button type="submit"><?php esc_html_e( 'Search', 'textdomain' ); ?></button>
</form>
The get_search_form documentation covers the arguments, and the template hierarchy explains when WordPress loads search.php instead of index.php. If your theme has no search.php, index.php renders your search results, which is why the heading often says “Category” or nothing at all.
Result design is not decoration. The search experience optimization framework treats the results page as the place where intent is either confirmed or abandoned. A count, the query, and a clear next step confirm it.
When to keep core and when to replace it
| Situation | Reasonable choice |
|---|---|
| Blog under a few thousand posts | Core, scoped with pre_get_posts |
| Documentation with descriptive titles | Core with search_columns limited to titles |
| Store where SKU search matters | Plugin or external index, not a meta LIKE |
| Archive over 50,000 posts | FULLTEXT index or external search |
| Multilingual site | External index with per-language analyzers |
| Site with one search box and no plans | Core, plus the empty-search guard |
Test the change on the front end
After any change, test the front end rather than the settings screen: search a term that should match, a phrase, a typo, and an empty submission. The functionality and speed check lists the broader pass. Search is one of the few features where the failure is visible in ten seconds, which makes it a good place to start.
What not to do
- Do not remove the noindex from search pages. The URL space is infinite and the pages are thin.
- Do not run
pre_get_postswithoutis_main_query(). Secondary queries inherit the change. - Do not set
posts_per_pageto-1on search. It loads the whole result set into memory. - Do not add an ungrouped
ORtoposts_search. It can expose drafts. - Do not index every meta key to “make search work”. You will trade a slow query for a slower one.
- Do not redirect every search to a landing page. Readers typed a specific phrase; answer it.
FAQ
Does WordPress built-in search cover custom fields?
No. Core searches post_title, post_excerpt, and post_content only. Custom fields, taxonomies, and comments are outside the query. Extending it requires the posts_search filter or an external index.
Why does my WordPress search return no results?
Usually because every term must match. Stopwords are dropped, but a term that appears only in an image caption or a custom field is invisible. Check the post type first: a post type with exclude_from_search set to true will never appear.
Are WordPress search results pages indexed by Google?
Not by default. Core adds noindex, follow to search results through wp_robots_noindex_search(). If your SEO plugin manages robots meta, confirm it keeps the same directive rather than turning search pages into indexable duplicates.
How do I make WordPress search more relevant?
Start with scope: restrict post types, drop the empty search, and decide whether body text belongs in the index. Core already ranks title matches above content matches. If that is not enough, a plugin or external index is the realistic next step.
Can I limit WordPress search to titles only?
Yes. Set search_columns to array( 'post_title' ) in pre_get_posts, or filter post_search_columns. The argument has existed since WordPress 6.2 and only accepts the three core text columns.
Why does ?s= show every post on the site?
An empty search term still sets is_search() and matches every row with LIKE '%%'. The page is noindexed but publicly reachable. Redirect empty searches to the homepage, or return an empty result set deliberately.
Is the built-in search fast enough for a large site?
For a few thousand posts, usually. Beyond that, the leading wildcard in LIKE '%term%' forces a scan of the posts table. Measure with Query Monitor before assuming; a full-text index or external search is the fix when the scan is the bottleneck.
Does WooCommerce use the WordPress search?
Product search runs through WP_Query like any other post type, so products are searchable if the post type is public. SKU, attributes, and variations live in meta tables, which core search does not read. That is why stores usually replace product search rather than tune it.