Can we sort store search results?

Highlighted
New Member
19 0 0

I know we can specify 'product', 'article' or 'page' to narrow our search results. But, is there some way to sort within one of those?

For example, if I set the shopify store search form to only return 'products', can I sort them by product type, or anything else?

0 Likes
Highlighted
Shopify Partner
13 0 8

Use sort option 'price' or 'title'. That is,

{% assign search_products = search.results | sort: 'price' %}

or

{% assign search_products = search.results | sort:'title' %}

So, the code looks like:

{% assign search_products = search.results | sort:'title' %}
{% for item in search_products %}
<!-- loop over each result -->
{% endfor %}
0 Likes
Highlighted
Tourist
5 0 1

The will sort by price ... in a manner of speaking.

Unfortunately, if you sort by price, you'll get clumps of articles, then clumps of parts that are sorted by price, then some more articles, then more parts sorted by price and so on. This is what happens when I use this code.

So needless to say, this code will not sort by 'price' correctly if you want to include 'blog articles' and 'pages' in the search.

 

0 Likes