By default, the WordPress search queries only the post_title and post_content columns in the wp_posts table. If you store important data in custom fields (post meta), those values are invisible to the search engine unless you extend it. Fortunately, three WordPress filters give you exactly the hooks you need — no plugin required.
Problem: The built-in WordPress search only queries post_title and post_content — custom fields stored in wp_postmeta are ignored, so posts with relevant metadata never appear in search results.
Solution: Extend the search query by hooking into posts_join to JOIN the wp_postmeta table, posts_where to add a meta_value LIKE %s condition, and posts_distinct to prevent duplicate results when a post has multiple matching meta rows.
Add the following three functions to functions.php:
1. JOIN the postmeta table
<?php
add_filter( 'posts_join', 'cf_search_join' );
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .= ' LEFT JOIN ' . $wpdb->postmeta
. ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
2. Extend the WHERE clause to include meta values
<?php
add_filter( 'posts_where', 'cf_search_where' );
function cf_search_where( $where ) {
global $wpdb;
if ( is_search() ) {
$where = preg_replace(
"/\(\s*" . $wpdb->posts . "\.post_title\s+LIKE\s*('[^']+')\s*\)/",
'(' . $wpdb->posts . '.post_title LIKE $1)'
. ' OR (' . $wpdb->postmeta . '.meta_value LIKE $1)',
$where
);
}
return $where;
}
3. Remove duplicate results
Because the JOIN can produce multiple rows per post (one per meta entry), you must add DISTINCT to avoid showing the same post twice:
<?php
add_filter( 'posts_distinct', 'cf_search_distinct' );
function cf_search_distinct( $where ) {
if ( is_search() ) {
return 'DISTINCT';
}
return $where;
}
All three functions work together: the JOIN makes the meta table available, the WHERE clause matches meta values the same way it matches post titles, and DISTINCT prevents duplicate results. The filters fire for both front-end searches and the admin edit-posts search screen.
NOTE: This approach searches all meta values, including internal WordPress fields like _edit_lock or serialized ACF data. For large sites with many post-meta rows, the LEFT JOIN can slow down searches noticeably. Consider restricting the join to specific meta_key values, or use a dedicated search plugin (e.g., SearchWP) if performance becomes an issue.