How can I display collections with a specific metafield value on a product page?

Topic summary

Goal: On the product page, list only those collections the product belongs to that have a specific metafield value (e.g., “Brand”).

Attempts (code-centric):

  • Loop over product.collections and check collection.metafields.custom.collectionType == Brand (unquoted). Output ends up showing only collections without any value in that metafield. OP notes the metafield renders like [“Brand”] / [“Speciale”] / [“Categoria”]. They also tried adding .value, without success.
  • Use a filtered array: product.collections | where: ‘collection.metafields.custom.collectionType’, ‘Brand’. This returns nothing.

Feedback received:

  • Suggestion to put the string in quotes: collection.metafields.custom.collectionType == “Brand”.

Current status:

  • OP confirms quoting (single and double) doesn’t fix it; still only sees collections lacking a value, even after trying .value. Metafield is defined as a single line text selected from a predefined list.

Notes:

  • Code snippets are central to the issue. No resolution yet; thread remains open with unanswered questions about correctly accessing/filtering the collection metafield value (possibly array vs. string behavior).
Summarized with AI on January 8. AI used: gpt-5.

Hello,

I want to show the lists of collections of the product on product page. But only collection with a metafield value. I try two options, but they doesn’t work.

1

{% for collection in product.collections %}
{% if collection.metafields.custom.collectionType == Brand %}
<b><a href="{{ collection.url }}">{{ collection.title }}</a>
</b>
{% endif %}
{% endfor %}

output of “collection.metafields.custom.collectionType” is [“Brand”] or [“Speciale”] or [“Categoria”], but this code show me only collections without any collectionType assigned.

2

{% assign filteredCollections = product.collections | where: 'collection.metafields.custom.collectionType', 'Brand' %}
{% for collection in filteredCollections %}
<b><a href="{{ collection.url }}">{{ collection.title }}</a>
</b>
{% endfor %}

this one do not show anything.

Any ideas?

Hello @Delio ,

For your first option, you will have to enclose Brand in quotes. Something like this

{% if collection.metafields.custom.collectionType == "Brand" %}

Thanks

Yash Garg

Hello @yashgarg ,

thank you for your answer but I had already tried both with superscript and double superscript, but it always gives me the only category with no value assigned in that metafield. I also tried adding .value but nothing.
The metafield is a single line type chosen from a list.