Search ONLY by meta key / meta values

You could do two things:

A) replace the search with a SQL query that only searches the postmeta table (faster as there’s no JOIN involved – you can get the post via it’s ID later on, when displaying the results).

B) Split the string right after WHERE 1=1 and drop the later part. You can use a simple return str_replace( $query_part_below, '', $search );.

 AND (
    (whirl_2_posts.post_title LIKE '%__SEARCH_STRING__%')  
    OR (whirl_2_posts.post_content LIKE '%__SEARCH_STRING__%')
)

Make sure that you properly $wpdb->prepare() before pushing it back in.

Leave a Comment