🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Add Sort by “Newest Product” option in Magento 2

By Sanjay JethvaUpdated on Jul 17, 2025 3 min read

It’s never ‘job done’ when it comes to providing exceptional customer experiences. It is necessary to offer out-of-the-box functionalities to customers for their convenience.

Bringing products with certain criteria to the top of the page can be particularly useful for customers who aren’t exactly sure what they want.

Default Magento 2 provides three options for product sorting on category page.

  • Product
  • Position
  • Name
1_default Magento 2 price sorting

To increase and maintain user efficiency, default sorting options are not enough. We have to make a remarkable effort to present more sorting facilities for customers.

Mostly customers are curious by nature and always affectionate towards browsing the latest products. Today, I’ve come up with the solution to add sort by newest product option in Magento 2.

Steps to Add Sort by Newest Product Option in Magento 2

1 . Create di.xml file in Vendor/Module/etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Config">
        <plugin name="Vendor_ModuleName::addCustomOptions" type="Vendor\Module\Plugin\Model\Config"/>
    </type>
    <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
        <plugin name="catalog_productlist_toolbar_plugin" type="Vendor\Module\Plugin\Product\ProductList\Toolbar"/>
    </type>
</config>

2 . Create Config.php file in Vendor/Modulename/Plugin/Model

<?php

namespace Vendor\Modulename\Plugin\Model;
use Magento\Store\Model\StoreManagerInterface;

class Config
{
    protected $_storeManager;

    public function __construct(
        StoreManagerInterface $storeManager
    )
    {
        $this->_storeManager = $storeManager;
    }

    public function afterGetAttributeUsedForSortByArray(\Magento\Catalog\Model\Config $catalogConfig, $options)
    {
        $customOption['newest_product'] = __('Newest Product');
        $options = array_merge($customOption, $options);
        return $options;
    }
}

3 . Create Toolbar.php file in Vendor/ModuleName/Plugin/Product/ProductList

change Vendor/ModuleName/Plugin/Product/ProductList/Toolbar.php
<?php

namespace Vendor\ModuleName\Plugin\Product\ProductList;

use Magento\Catalog\Block\Product\ProductList\Toolbar as Productdata;

class Toolbar
{
    public function aroundSetCollection(Productdata $subject, \Closure $proceed, $collection)
    {
        $currentOrder = $subject->getCurrentOrder();
        if ($currentOrder) {
            if ($currentOrder == "newest_product") {
                $direction = $subject->getCurrentDirection();
                $collection->getSelect()->order('created_at ' . $direction);
            }
            return $proceed($collection);
        }
    }
}

Following the above steps, you can see the sort by newest product option in Magento 2 category page as shown below:

add sort by newest product option in Magento 2

If you are using a new version of Magento (2.4.4 onwards), the above method may not work properly. In such cases, follow these steps:

  • In eav_attribute table, find the created_at product attribute and set its frontend_label column value to Created At.
  • In the catalog_eav_attribute table, find the created_at product attribute, and set its used_for_sort_by column value to 1.
  • Clear Magento 2 cache.

You can also do this by using the following SQL Query:

# Get the attribute_id of 'created_at'
select attribute_id from eav_attribute where attribute_code = 'created_at' and entity_type_id=4;

# Set frontend_label
update eav_attribute set frontend_label = 'Created At' where attribute_id=112;

# Set used_for_sort_by
update catalog_eav_attribute set used_for_sort_by = 1 where attribute_id=112;

That’s all!

Also, let me know if you found any positive impact on the purchase of new products after implementing the solution.

Please do consider sharing this post with the Magento Community via social media. Thank You.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.