Shopify themes, liquid, logos, and UX
So I have pages created by metobjects, and am trying to create a page to index these with a bit of liquid code. All works fine - except it seems I can only sort on text fields where as I need to sort on a date eg I have created metaobjects with field "publication_date", i then sort that as follows:
{% assign mags = mags | sort: 'publication_date' %}
Outputting with a For loop:
{% for myMag in mags %} {{myMag.publication_date }} <br> {% endfor %}
Results in:
2013-03-01
2014-03-01
2014-03-01
2012-12-01
2013-12-01
2012-02-01
2014-01-01
2013-05-01
2012-11-01
2012-10-01
2013-09-01
2016-10-01
2013-11-01
2015-12-01
2016-07-01
2021-03-01
2014-12-01
2021-03-01
2014-12-01
2014-12-01
2014-01-01
2014-11-01
2012-10-01
2013-12-01
2015-02-01
2014-12-01
2014-06-01
2016-05-01
2019-02-01
and not the following that i'd expect/like:
2012-02-01
2012-10-01
2012-10-01
2012-11-01
2012-12-01
2013-03-01
2013-05-01
2013-09-01
2013-11-01
2013-12-01
2013-12-01
2014-01-01
2014-01-01
2014-03-01
2014-03-01
2014-06-01
2014-11-01
2014-12-01
2014-12-01
2014-12-01
2014-12-01
2015-02-01
2015-12-01
2016-05-01
2016-07-01
2016-10-01
2019-02-01
2021-03-01
2021-03-01
I thought it might be to do with the Sort function not interpreting the Data type - so have tried adding a different field with the dates entered as an Integer without the dashes - but result is the same. If I sort on a text field it sorts that field alphabetically without any issues - just not numbers.
What am I missing?!
In case anyone has similar issue - it seems that sort() only works on text datatypes - adding a field of type "single line text", and entering the date without the number then the above gives the following expected result:
20120201
20121001
20121001
20121101
20121201
20130301
20130501
20130901
20131101
20131201
20131201
20140101
20140101
20140301
20140301
20140601
20141101
20141201
20141201
20141201
20141201
20150201
20151201
20160501
20160701
20161001
20190201
20210301
20210301
So it seems like a bug - and the workaround is to use a text field...frustrating!
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024