Hello! I am new to this forum and to coding as well. I am trying to resolve some issues with this piece of code that I believe runs how my search works. I want the search to search terms in the title and contents and retrieve the results. The problem I am having is that if there is an empty space in front of something it does not search right. As in "dell laptop". If you search for "laptop dell" you get no results. And if you search only " dell" with the empty space in front of it, you get no results if 'dell' is at the beginning of the title. I want the search to search all words and mix the results, but also I was having the problem that if i searched for "dell laptop" I would get results for dell and laptop, bringing up gateway/sony and others because it was streaming from the 2 results instead of them both as 1 result together (for each result it brings back to the screen of course). Here are different strands of code used. Newest on bottom.....any help? I am lost!




//////////////////////////////////////////////////////////

function Theme_posts_where( $where ) {

global $wpdb, $term;
$where .= " AND ({$wpdb->posts}.post_title LIKE '%$term%' OR {$wpdb->posts}.post_content LIKE '%$term%')";

return $where;
}


//////////////////////////////////////////////////////////

function Theme_posts_where( $where ) {

global $wpdb, $term;
$term1 = explode(" ",$term);
$xl = '';

foreach($term1 as $tt)
{
$xl .= " OR ({$wpdb->posts}.post_title LIKE '%$tt%' OR {$wpdb->posts}.post_content LIKE '%$tt%')";

}

$where .= " AND (({$wpdb->posts}.post_title LIKE '%$term%' OR {$wpdb->posts}.post_content LIKE '%$term%') $xl )";

return $where;
}