How to use Magento2 Collection

May 14, 2013   //   by kdecom   //   magento, magento2, magento2-tutorial  //  No Comments

Here i will show you some tips and trick regarding magento2 collection

Here is what i was doing it for my magento2 product question answer extension.

i need the list of the question for that particular product to displaying on the product page.

What we used to do in old magento version

->addAttributeToFilter(‘product_id’, $id)
->addAttributeToFilter(‘status’, ‘published’)

but it didnt worked in magento2.

After doing some research of magento code i figure out instead of using addAttributeToFilter you should be using addFieldToFilter so i did replace it with

->addFieldToFilter(‘product_id’, $id)
->addFieldToFilter(‘status’, ‘published’)


I will come up with more as i will know more ..

Leave a comment