Magento has a powerful set of methods to filter collections. Since there are two types of Objects that can be contained in collections, we must first determine which type of data we are working with before we can filter it. Magento implements a EAV data model for entities such as products and categories. There is a different set of methods to use if we are filtering a collection of EAV Objects.
In Magento, Orders are not stored as EAV Objects. This makes the orders collection a good example for filtering a basic collection.
$collection_of_orders = Mage::getModel('sales/order')->getCollection(); $collection_of_orders->addFieldToFilter('status','processing');
If we look at the products collection, we can see that the products are stored in an EAV data model. We can easily filter by EAV attributes as well.
$collection_of_products = Mage::getModel('catalog/product')->getCollection(); $collection_of_products->addAttributeToFilter('visible',1);