79500529

Date: 2025-03-11 11:19:22
Score: 0.5
Natty:
Report link

A similar question was asked here.

https://community.shopify.com/c/shopify-design/sorting-number-in-natural-order-in-collections/m-p/1850181

Since the values are likely being treated as strings the order isn't based on numeric values (but string values).

This is verbose code I've just smashed out that for production would need to be cleaned up, added whitespace control and made more efficient - but should be easier to read for this thread.

{% assign myArray = "11,7,4,3,12,9,2,8,6,10,1,5" | split:"," %}
{% assign myNewArray = "" %}
{% assign zeroFill = "00000000" %}

{% for i in myArray %}
  {%  assign thisFill = zeroFill | slice:i.size, zeroFill.size %}
  {%  assign newValue = thisFill | append:i | append:"," %}
  {%  assign myNewArray = myNewArray | append:newValue %}
{%  endfor %}

{% assign  myNewArray = myNewArray| split:"," | sort %}

{%  for i in myNewArray %}
{{  i | abs  }}<br />
{%  endfor %}

Does that help?

I also touch on something similar here.
https://freakdesign.com.au/blogs/news/sort-products-in-a-shopify-collection-by-metafield-value-without-javascript

He adds zeros to each number in order to work around the issue.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: ofir baruch