Magento 2 collection order by Id– It is very simple to set order by clause in Magento 2. We can use setOrder ASC or DESC in Collection. Here in this article, we are going to explain how you can get collection data order by ASC or DESC.
Magento 2 collection order by | Id | ASC | DESC Example
Here is example of product collection order by price ASC, DESC-
Collection order by ASC
Here is an example of order by asc clause in collection-
Magento 2 collection order by | ASC | Example:
$colletion = $productionCollection->getCollection(); $colletion->addFieldToFilter('store_id', 1); $colletion->setOrder('price','ASC'); |
Collection order by DESC
Here is an example of order by desc clause in collection-
Magento 2 collection order by | ASC | Example:
$colletion = $productionCollection->getCollection(); $colletion->addFieldToFilter('store_id', 1); $colletion->setOrder('price','DESC'); |
Magento 2 collection Set order by Not Working?
If order by clause not working check collection & order by column.