product data shopify

How To Filter Articles And Products By Tag On Shopify

This article will show you how to filter products and posts using tags.

Filter Products By Tag

To filter products by a certain tag, you can access the following path:
Remember to replace “collection-slug” with the slug of the Collection you are testing.

Collection with only 1 tag

Template you need to edit: collection.liquid


Filter in 1 collection with multiple tags


Filter Posts By Tag

Filter in 1 category only 1 tag

Template you need to edit: blog.liquid


Filter in 1 category with many tags


Process Data

Once you have visited such path, to create the filter you can do the following:

The current_tags value is a collection of tags like Array so we can look up.

In case there is only 1 tag, you just need to call current_tags | first is going out.

In case there are many tags, we will need to run through the loop:

{% for tag in current_tags %}
  {{ tag }}
{% endfor %}

For example, an article needs to meet the criteria of having a tag to be displayed on that filter tag page

{% for article in blog.articles %}
  {% for tag in current_tags %}
    {% if article.tags contains tag %}
      {% include 'product-card' %}
    {% endfor %}
  {% endfor %}
{% endfor %}

Below is the guideline for filtering articles, hope this guide help you