Shopify themes, liquid, logos, and UX
I want all my collection pages to sort the products by default so that all products on sale are shown last in the collection. I have a metafield on my products with sale true/false to know which products are on sale or not. I tried to make a loop over the products in the collection page and sort the products on sale last. It was working, but pagination is the problem. It sorted all products for each page with the products on sale last, So each page was sorted separately, but I want all products on sale to show in the very end of the collection on the last pages. My loop obviously only sorted each page instead of the whole collection.
Hey @GlennAppsal,
Could you not assign the array to a variable first, sort it by the metafield and then loop over it?
Example code:
{% assign products_by_metafield = collection.products | sort: "your_meta_field" %}
{% for product in products_by_metafield %}
<h2>{{ product.title }}</h2>
{% endfor %}
Did you figure this out? I am having the same exact issue right now and do not have a meta field for on sale products so it’s a little more difficult. We also have pagination…
No, didnt find any solution that worked with the pagination
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025