There is no easy way to do this without modifying the main search query that was generated by wordpress. I think you should go for posts_search
& posts_join
hook. They are located in wp-includes/query.php
Do a var_dump
first to see what you are getting & modify accordingly. Here’s some untested code i could put up right now to get you started.
add_filter('posts_search', 'search_function', 10, 2);
function search_function($search, $query) {
if(is_admin() || !$query->is_main_query() || !$query->is_search)
return; //determine if we are modifying the right query
global $wpdb;
$search_term = $query->get('s');
$search=" AND (";
//point 1
$search .= "($wpdb->posts.post_content LIKE '%$search_term%')";
//need to add an OR between search conditions
$search .= " OR ";
//point 2
$search .= "($wpdb->comments.comment_content LIKE '%$search_term%')";
//need to add an OR between search conditions
$search .= " OR ";
//point 3
$search .= "($wpdb->postmeta.meta_key = 'custom_field_key' AND $wpdb->postmeta.meta_value LIKE '%$search_term%')";
//need to add an OR between search conditions
$search .= " OR ";
//point 4
$search .= "({$wpdb->prefix}notes.text LIKE '%$search_term%')";
//add the filter to join, sql will error out without joining the tables to the query
add_filter('posts_join', 'join_tables');
return $search . ') ';
}
function join_tables($join) {
$join .= "JOIN $wpdb->comments ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)";
$join .= "JOIN $wpdb->postmeta ON ($wpdb->postmeta.post_ID = $wpdb->posts.ID)";
$join .= "JOIN {$wpdb->prefix}notes ON ({$wpdb->prefix}notes.post_ID = $wpdb->posts.ID)";
return $join;
}