How can I use tag filtering to populate a collection object in Liquid?

Topic summary

A developer is trying to use Liquid to populate a collection object based on tag filtering in Shopify. They want to display related products on a product page by filtering products that share a specific tag (e.g., “related-baseball-hats”).

Current approach attempted:

  • Using a URL structure like /collections/all/related-baseball-hats to view tagged products
  • Trying to assign filtered products using Liquid syntax similar to:
{% assign my_tagged_products = collection.products | where: "tags", "related-baseball-hats" %}

Key questions:

  • Is it possible to return a collection based on tag filtering using Liquid?
  • What is the correct markup to achieve this?

The discussion remains open with no responses yet. The user is seeking guidance on the proper Liquid syntax and whether this filtering approach is feasible within Shopify’s theme development framework.

Summarized with AI on November 21. AI used: claude-sonnet-4-5-20250929.

using Tag Filtering, how would I populate a collection object in liquid? For example, say we have a related tag we’re using lets say related-baseball-hats using https://www.mydomain.com/collections/all/related-baseball-hats I can see them all in search. But if I have a product and I pull the tag out, how can I bring back these related products into a collection to show on the product page. Is it possible to use liquid to return a collection based on tag filtering? What is the correct markup.

Thanks!

I was hoping something like this would work?

{% assign my_tagged_products = collection.products | where: "tags", "related-baseball-hats" %}

https://shopify.dev/docs/themes/navigation-search/filtering/tag-filtering