I am trying to use AND and OR based on user input.
OR = success
But I an unable to setup AND queries for addFieldToFilter
question: how can I add the second (looped filter) using AND to join
$search_array = array();
$or_array = array();
if (is_numeric($query)) {
// this becomes OR and is great
$search_array[] = array('attribute' => 'entity_id', 'eq' => $query);
$search_array[] = array('attribute' => 'sku', 'like'=>'%'.$query.'%');
} else {
if (strpos($query, ' ') !== false) {
$morewords = explode(" ", $query);
foreach ($morewords as $word) {
// This needs to be AND clause - need help
$search_array[] = array('attribute' => 'sku', 'like'=>'%'.$word.'%');
}
} else {
$search_array[] = array('attribute' => 'sku', 'like'=>'%'.$query.'%');
}
}
$collection->addFieldToFilter($search_array);