Better Search enhances WordPress’s native search capabilities to deliver more relevant results to visitors. At the heart of this functionality is the Better_Search_Query class, which you can use for optimal search performance on your site.
What is Better_Search_Query?
The Better_Search_Query class extends WordPress’s native WP_Query class, significantly improving search relevance and performance. It implements MySQL’s FULLTEXT indexing and provides advanced search operators that help users find relevant search results.
Implementing Better_Search_Query in Your Theme
Basic Implementation
To use Better_Search_Query in your theme, you can create a custom search template:
Advanced Configuration
For more control, you can configure Better_Search_Query with additional parameters. You can also post most WP_Query parametersOpens in a new window.
Post statuses and caching
On the front end, a caller-supplied post_status is restricted to public statuses when the current user lacks edit_others_posts. Queries that include attachments may also use inherit. An empty selection falls back to publish, or to publish and inherit when attachments are included.
Admin searches retain WordPress’s own status and capability handling. The plugin’s result cache includes the effective post statuses after restriction, so requests with different allowed statuses do not share the same cache entry.
Advanced Features
Using Boolean Operators
Better Search supports MySQL’s Boolean mode for complex searches:
+word: Word must be present-word: Word must not be present>word: Increases relevance of word<word: Decreases relevance of word*: Wildcard for partial matching"phrase": Exact phrase matching
Troubleshooting
No Results Found
If your searches return no results, check these common issues:
- Query Errors: See Debugging with Query Monitor to understand how to identify the Better Search Query.
- FULLTEXT Indexing: Ensure your database tables have FULLTEXT indexes enabled. You can recreate these in the Tools page.
- Post Types: Verify that the post types you’re searching for are included in your query parameters.
Performance Optimization
For large sites, consider these performance tips:
- Limit Search Fields: Include only the necessary fields.
- Cache Results: Implement a caching mechanism for search results. WP_Query now supports caching via the object cache.
- Paginate Results: Use pagination to limit the number of results per page.

Understanding Better Search Templates
Better Search Settings: Search