Hello, I have a metaobject for a list of events. I want to output them in date order. I can’t find how to sort them by date. Default output is by object create date, which does not work.
Not sure if this helps, but I came across a similar problem trying to sort metaobjects in a particular order different from alphabetical.
I found out that the “sort” filter always casts to string in order to compare for sorting. Maybe you can cast your dates into string (like timestamp or smth) and try to apply the filter to that directly.
+1 Would love to hear what the answer to this is as well. I looked everywhere for a way to do this - I’m sure I’m missing something simple, but I’m genuinely stumped.
There is no native way of sorting a metaobject by created_at/updated_at field, as it is not even existent for liquid.
BUT, if you already have a date field in an event object, there is a workaround using that.
Just output whatever events you have, without sorting, and assuming you have something like event-card, add to its container a css style “order” with a date as a value. Format the date to start with the year and end with the smallest unit, i.e. 30 May 2025 09:00 → 2505300900. The css style then would be (for this specific event) order: 2505300900. The outer container, holding all event-cards should have display: flex.
For now metaobjects are sorted by their handles ascending, since nobody really sees the handle you can add a number in the front to force an order. This works with pagination which is nice since sorting liquid arrays wouldn’t and using storefront api for a simple fixed sort is pretty annoying.
Hopefully Shopify will give use real sorting at some point… but their AI doesn’t even think metaobjects can paginate so it might not be a priority
Metaobjects can be sorted, but you have to sort by the field handle itself. Also, make sure the variable names are the same. Do the assignments, then sort on the date field.