Is it possible to sort a collection by tag?

DoiKikuta
Tourist
7 0 1

Hello. I'm trying to implement a little feature to sort collections by a specific tag. Let me explain further:

 

This is not about filtering. Besides being able to sort by price and name, I would like to select a sort option that allows me to show products with a certain tag FIRST and then everything else.

 

Example: I have 5 products in the collection. Three of those products have the tag "purple", another one has the tag "green" and the last one has the tag "yellow". When selecting the "Sort by Purple" option from the select form, I would like the purple objects to show up first in the template, and then all the other ones (green and yellow) in no specific order.

 

Is it possible to do this? What would be the best course of action to achieve it? I know this is not ideal, but it's something that the client would like to have.

 

Thank you.

0 Likes