function __adapted_search_function($search, $query) {
if (is_admin() || !$query->is_main_query() || !$query->is_search) {
return;
}
global $wpdb;
$search_term = $query->get('s');
$search = " AND (";
$search .= "({$wpdb->posts}.post_title LIKE '%$search_term%')";
$search .= " OR ";
$search .= "({$wpdb->posts}.post_excerpt LIKE '%$search_term%')";
$search .= " OR ";
$search .= "({$wpdb->postmeta}.meta_key = 'findergg' AND $wpdb->postmeta.meta_value LIKE '%$search_term%')";
$search .= ") ";
add_filter("posts_join", '__custom_join_tables');
add_filter('posts_where', 'posts_where');
add_filter('posts_fields', 'custom_posts_fields');
return $search;
}
function posts_where($where) {
global $wpdb;
$keywords = get_query_var('s');
$newout = $keywords;
$newout = "+";
$newout .= str_replace(" ", "+", $keywords);
$where = " AND {$wpdb->posts}.post_status = 'publish' AND MATCH(wpma.meta_value) AGAINST ('$newout' IN BOOLEAN MODE) ";
return $where;
}
function __custom_join_tables($joins) {
global $wpdb;
$joins .= " JOIN $wpdb->postmeta AS wpma ON (wpma.post_ID = {$wpdb->posts}.ID) ";
return $joins;
}
function custom_posts_fields($fields) {
global $wpdb;
$fields = " {$wpdb->posts}.post_title, {$wpdb->posts}.post_content ";
return $fields;
}
add_action('posts_search', '__adapted_search_function', 1, 2);