| Parameter | Details |
|---|---|
| $addFieldToFilter($field, $condition = null) | { string } The field we are adding to the filter. |
| $addFieldToFilter($field, $condition = null) | { mixed } The definition of the filter we will use. |
| addAttributeToFilter($attr, $condition = null, $join = 'inner') | { string } The field we are adding to the filter. |
| addAttributeToFilter($attr, $condition = null, $join = 'inner') | { mixed } The definition of the filter we will use. |
| addAttributeToFilter($attr, $condition = null, $join = 'inner') | { ('inner','left') } The type of sql join to use when joining the EAV table. |
Filter Comparison Arguments
Magento also offers a flexible way of filtering using comparison operators as well. Here is a list of valid operators and their syntax:
All comparison arguments can be passed to the second parameter of either the addFieldToFielter() or addAttributeToFilter() methods.
$collection_of_products->addAttributeToFilter('visible',array("eq"=>1));
| Comparison | Argument Array | Resulting SQL Snippet |
|---|---|---|
| Equals | array("eq"=>$var) | WHERE (`my_field` = $var) |
| Not Equal | array("neq"=>$var) | WHERE (`my_field` != $var) |
| Like | array("like"=>$var) | WHERE (`my_field` LIKE $var) |
| Not Like | array("nlike"=>$var) | WHERE (`my_field` NOT LIKE $var) |
| Is | array("is"=>$var) | WHERE (`my_field` IS $var) |
| In | array("in"=>$var) | WHERE (`my_field` IN($var)) |
| Not In | array("nin"=>$var) | WHERE (`my_field` NOT IN($var)) |
| Null | array("null"=>true) | WHERE (`my_field` IS NULL) |
| Not Null | array("notnull"=>true) | WHERE (`my_field` IS NOT NULL) |
| Greater Than | array("gt"=>$var) | WHERE (`my_field` > $var) |
| Less Than | array("lt"=>$var) | WHERE (`my_field` < $var) |
| Greater Than or Equal | array("gteq"=>$var) | WHERE (`my_field` >= $var) |
| Less Than or Equal | array("lteq"=>$var) | WHERE (`my_field` <= $var) |
| Find in Set | array("finset"=>array($var)) | WHERE (find_in_set($var,`my_field`) |
| From and To | array("from"=>$var1, "to"=>$var2) | WHERE (`my_field` >= $var1 AND `my_field` <= $var2) |