I'm trying to filter products by a custom attribute, but the addFieldToFilter isn't working. I get an error "Error filtering template: Warning: Illegal string offset 'attribute'"
Where am I going wrong?
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); $productCollection->addFieldToFilter( array('attribute'=>'engine_store_show_on_homepage','eq'=>1) ); $productCollection->load(); echo "<pre>";print_r($productCollection->getData()); //print product collection
I appreciate others have asked the same question, but I don't understand the answers given as they all require a class or module to be created. I'm trying to do this within a template .phtml file.