Shopify themes, liquid, logos, and UX
I have created a custom metafield for collections with the type of Integer in admin. I am trying list the collection names and order them by the new custom metafield. Unfortunately the sorting does't apply. Am I missing something?
Solved! Go to the solution
This is an accepted solution.
Hi @kelliott ,
Shopify doesn't support this one. You can refer code below:
{% assign sorted_collections = '' %}
{% for collection in collections %}
{% assign colTitle = collection.title %}
{% assign colUrl = collection.url %}
{% assign sorted_collections = sorted_collections | append: collection.metafields.custom.menu_sort.value | append: "," | append: colTitle | append: "," | append: colUrl | append: ";" %}
{% endfor %}
{% assign arrCollection = sorted_collections | split: ";" | sort_natural %}
{% for col in arrCollection %}
{% assign collectionArr = col | split: "," %}
<div class="order-form__collections-item">
<a href="{{ collectionArr | last }}">{{ collectionArr[1] }}</a>
</div>
{% endfor %}
This is an accepted solution.
Hi @kelliott ,
Shopify doesn't support this one. You can refer code below:
{% assign sorted_collections = '' %}
{% for collection in collections %}
{% assign colTitle = collection.title %}
{% assign colUrl = collection.url %}
{% assign sorted_collections = sorted_collections | append: collection.metafields.custom.menu_sort.value | append: "," | append: colTitle | append: "," | append: colUrl | append: ";" %}
{% endfor %}
{% assign arrCollection = sorted_collections | split: ";" | sort_natural %}
{% for col in arrCollection %}
{% assign collectionArr = col | split: "," %}
<div class="order-form__collections-item">
<a href="{{ collectionArr | last }}">{{ collectionArr[1] }}</a>
</div>
{% endfor %}
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025