Remove the post_content search from WHERE clause (and CONCAT sql function)
I've a custom table and by following the instructions on this page https://codex.wordpress.org/Custom_Queries I was able to modify the WHERE clause.
function geotag_search_where( $where ){
if( is_search() ) {
$where = preg_replace( "/\(\s*" . $wpdb-posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
" CONCAT( posts.post_title, customtable.customfield) LIKE $1 ", $where );
}
return $where;
}
add_filter('posts_where', 'geotag_search_where' );
My only problem is that wordpress keeps the OR (posts.post_content LIKE '%searchterm%')
and this slows down my search time. Is there a way to modify the preg_replace()
so that it will exclude also the post_content? Thanks!
EDIT [as per @Prosti request]
Here is how is now my WHERE clause
SELECT [normal select from worpress]
….
[customized from my filters]
LEFT JOIN customtable ON FIND_IN_SET(posts.ID, customtable.postID) 0
WHERE 1=1
AND (term_relationships.term_taxonomy_id IN (7) )
AND (( CONCAT(posts.post_title, customtable.customfield) LIKE '%searchterm%'
OR (posts.post_content LIKE '%searchterm%')))
[end of customization]
…….
AND [rest is normal from worpress]
I would like to exclude the OR (posts.post_content LIKE '%searchterm%')
so that sql would be:
....
AND (( CONCAT(posts.post_title, customtable.customfield) LIKE '%searchterm%' ))
....
Topic posts-where filters Wordpress search
Category Web