How can I sort products in a collection by updated-date?

How can I sort products in a collection by updated-date?

yoonlaser
Shopify Partner
39 0 15

I have a 'Deals' page made from 'deals' tag -> 'deals' automated collection.
So the condition for the collection is

1. title doesn't contain 'used' - we have 'Refurbished' page separately, so excluded the used item

2. Compare at price > 0

3. Compare at price not empty

So Deals collections shows only the sales items, but when I set the product sort to be 'newest' it shows recently created items first. 

We schedule sale price to be on/off, but mostly those are not newly created items. So new sales items don't show up on top even though the sale just started.
I need to have a product sort option something like 'newest - update'.

I looked into Flow, but there's no option to manipulate collection list. My theme doesn't support that kind of feature.
How can I achieve this?

 

Replies 2 (2)

Small_Task_Help
Shopify Partner
969 39 93

Hi,

Update Metafield with Custom Code - You can use Shopify's admin API or Storefront API with a custom script that updates last_updated metafield whenever sale price changes.

 

Script example

 

{% assign sorted_products = collection.products | sort: 'metafields.namespace.last_updated' %}
{% for product in sorted_products %}
  <!-- Your code to display products -->
{% endfor %}

 

To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad
yoonlaser
Shopify Partner
39 0 15

Hello,
Thank you for your help first of all.
I'm trying to implement this by liquid code, but looks like there's some restrictions.
I added a metafield and added your code a bit edited, but the sort by metafield part doesn't work now.
I searched Perplexity, and Copilot to ask if it's possible to sort by metafield, but both said it's not possible.
Have you tried this way and it worked or do you know any work around instead of using the liquid on this?

Thank you!