How to sort meta objects by date in coding?

Jeff67
Shopify Partner
6 0 3

I'm trying to sort a meta object by date.

 

{% assign sorted_shows = shop.metaobjects.shows.values | sort: 'show.date' | reverse %}

{% for shows in sorted_shows %}
{{ shows.date }} <br>
{% endfor %}

 

These are the results I get:

 

2024-02-09
2025-01-10
2024-02-01
2024-01-26
2024-02-16

 

any ideas?  I'm stumped 

Reply 1 (1)

Jeff67
Shopify Partner
6 0 3

From what I have learned Shopify has a glitch when it comes to sorting by Date. This fixes the issue.

 

{% assign sorted_shows = shop.metaobjects.shows.values | sort_natural: 'date' %}

{% for shows in sorted_shows %}

{{ shows.date }} <br>

{% endfor %}