Sort by best selling homepage (Liquid code)

Bumpyshot
New Member
6 0 0

Hi,
I want to display all products from my shop with best-selling products first on my home page. I know I can create a collection with all my product and sort them by best selling, but I don't want to use this method because is not SEO friendly for my website. So I intend to use sort: / sort_by in my code to display the best selling product, but I didn't manage to get them...
For now, this is part of my code :

 

{%- assign collection = collections.all  -%}

 

this code gets all my product from my website. After that I try to display the product with :

 

{% for product in collection.products %}

 

It works perfectly, but I want to be sorted by best selling product, this is some example i try:

 

{% for product in collection.products | sort: 'best-selling' %}
{% for product in collection.products | sort_by: 'best-selling' %}

 

 Any idea how to make this code work?

Reply 1 (1)

tim202
Shopify Partner
31 4 3

Same here been doing this also but no luck, the sort filter doesn't support collection right now.
Best option is to create a collection that has been sorted to best-selling 

Capture.JPG

then just display it in Liquid

 

 

{% assign best-selling= collections.best-selling-product-collection.products  %}
{% for product in best-selling limit:3 %}
....
{% endfor%}