Magento – Get all featured products collection

featured-productmagento-1.9product-collection

I am trying to retrieve all the featured product like this in my .phtml block:

$collection = Mage::getResourceModel('catalog/product_collection')
                           ->setStoreId(Mage::app()->getStore()->getId())
                           ->addAttributeToFilter('featured_product', array(1))
                           ->addAttributeToFilter('status', array(1));

But i keep getting an error like this:

PHP Fatal error: Uncaught Error: Call to a member function
getBackend() on boolean in
/var/www/gv/app/code/core/Mage/Eav/Model/Entity/Abstract.php:816\nStack
trace:\n #0
/var/www/gv/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1377):
Mage_Eav_Model_Entity_Abstract->isAttributeStatic('featured_produc…')\n#1
/var/www/gv/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(321):
Mage_Eav_Model_Entity_Collection_Abstract->_getAttributeConditionSql('featured_produc…',
Array, 'inner')\n#2
/var/www/gv/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(1440):
Mage_Eav_Model_Entity_Collection_Abstract->addAttributeToFilter('featured_produc…',

Best Answer

This is tested code on 1.9.x

 $collection = Mage::getResourceModel('productslider/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('featured', array('eq' => '1'))
                 ->addAttributeToFilter('status', array(1)) ;
        foreach($collection as $product){

            echo '<pre>'; print_r($product->getName()); die('ok');
    }
Related Topic