1

I am trying to fetch product collection based on crated custom attribute that is is_home_page.

Check by below code.

echo "<pre>";
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->addAttributeToFilter('show_on_home_page',['eq'=>'1'])
->setPageSize(4)
->setOrder('sort_order','DESC')
->load();

So, here what i need is Currently i want to display products on home page which product has attribute set to Yes.

I can able to get collection of products which has attribute Yes.

But i would like to get collection in order to last updated product.

how can i achieve this ?

4

This will do for you

 $productCollection->addAttributeToSort('update_at', 'DESC')
0
4

Try with

->addAttributeToSort('updated_at', 'DESC')

instead of

->setOrder('sort_order','DESC')
1
  • we do have feature in manual sort & automatic sort in EE how we need to fetch products by manual sort? prnt.sc/xothut please advise
    – Nagaraju K
    Jan 27 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.