query_vars['s'])) { $q = $wp_query->query_vars; $q['s'] = addslashes_gpc($q['s']); $search = ' OR ('; $q['s'] = preg_replace('/, +/', ' ', $q['s']); $q['s'] = str_replace(',', ' ', $q['s']); $q['s'] = str_replace('"', ' ', $q['s']); $q['s'] = trim($q['s']); if ($q['exact']) { $n = ''; } else { $n = '%'; } if (!$q['sentence']) { $s_array = explode(' ',$q['s']); $q['search_terms'] = $s_array; $search .= ' (comment_content LIKE \''.$n.$s_array[0].$n.'\')'; for ( $i = 1; $i < count($s_array); $i = $i + 1) { $search .= ' AND (comment_content LIKE \''.$n.$s_array[$i].$n.'\')'; } $search .= ' OR (comment_content LIKE \''.$n.$q['s'].$n.'\')'; $search .= ') '; } else { $search = ' OR (comment_content LIKE \''.$n.$q['s'].$n.'\') '; } $where .= $search; } return $where; } function add_comments_search_join($join) { global $wp_query, $wpdb; if (!empty($wp_query->query_vars['s'])) { $join .= "LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1') "; } return $join; } add_filter('posts_where', 'add_comments_search_where'); add_filter('posts_join', 'add_comments_search_join'); ?>