magento product collection addAttributeToFilter conditionals

Magento addAttributeToFilter with conditions of greater than, less than, greater than and equal to, less than and equal to, not equal, like, not like, is not null, is null, equal to.

$_products = Mage::getModel('catalog/product')->getCollection()
	->addAttributeToSelect('*')
	->addAttributeToFilter('entity_id', array('in' => array(5114,7138,7157,7231,7343,7363))) // IN 
	->addAttributeToFilter('entity_id', array('nin' => array(1111,2222,3333)))	// NOT IN
	->addAttributeToFilter('entity_id', array('gt' => 1000))	// greater than >
	->addAttributeToFilter('entity_id', array('lt' => 9999))	// less than <
	->addAttributeToFilter('entity_id', array('gteq' => 1000))	// greater than and equal to >=
	->addAttributeToFilter('entity_id', array('lteq' => 9999))	// less than and equal to <=
	->addAttributeToFilter('sku', array('neq' => '12345'))		// not euqal
	->addAttributeToFilter('name', array('like' => '%of%'))		// LIKE
	->addAttributeToFilter('name', array('nlike' => 'aaaa%'))	// NOT LIKE
	->addAttributeToFilter('name', array('notnull' => true))	// IS NOT NULL
	//->addAttributeToFilter('description', array('null' => true))// IS NULL
	->addAttributeToFilter('status', array('eq' => 1))			// equal to
	->addAttributeToFilter('visibility', 4)						// equal to 
	->load();
//echo $_products->getSelect();

foreach($_products as $p) {
	echo $p->getName() . "  " . $p->getSku() . " " . $p->getPrice() . " " . $p->getProductUrl() . $p->getVisibility() . "<br>";
}

Search within Codexpedia

Custom Search

Search the entire web

Custom Search