Get collections by meta fields(I want to filter 'vendor' collections by a custom field 'region')

Topic summary

A user seeks to filter and retrieve collections based on a custom metafield called ‘region’ (specifically wanting to show only collections where region equals ‘Alabama’).

Key Points:

  • Metafields on collections are accessible via Liquid templating
  • The proposed loop approach has limitations: it won’t cover all collections in shops with large inventories and may have performance issues
  • A working solution was provided:
    1. Create custom metafield named ‘region’ in Shopify dashboard (Online store > Themes > Edit code)
    2. Locate the list-collections-template file
    3. Find instances of {%- render 'collection-grid-item' and wrap them with conditional logic
    4. Use {% unless collection.metafields.custom.region == "alabama" %} to filter collections

Implementation Note: The code appears multiple times in the template, so all instances need updating. However, concerns remain about whether this approach is optimal given the context and what the user is ultimately trying to achieve.

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

Hi,

I don’t know how to retrieve collections with a particular meta field.

For example, I want to only get collections with a meta field ‘region’ equal to ‘Alabama’.

{% for collection in collections %}
{% if collection.metafields.region.alabama %}
{% assign alabama_vendors = 'alabama'%}
{% endif %}
{% endfor %}

How can I conditionally retrieve collections by their meta field?
Is it even possible to access collections’ meta fields?

Best

1 Like

The metafields on a collection are certainly accessible via Liquid. I use them all the time.

However that loop you’re doing will have a limit and if your shop has lots of collection it’s possible (and likely) that the loop won’t cover them all. I would also say it’s not a very performant bit of code.

Looking at the code it’s not clear what you’re trying to achieve. I see a variable being set but given the simplicity I wonder if there’s a better way to approach it. Feel free to post back with some more context.

1 Like

Hi @begginer1231 ,

Yes, You can.

Please follow below steps:

  1. From Shopify dashboard, go to Online store > Themes > Edit code

  2. Create custom metafield with name region

  3. In the search box, search for the file named list-collections-template

  4. Search term {%- render ‘collection-grid-item’ and edit code with below script

{% unless collection.metafields.custom.region == "alabama" %}
   {%- render 'collection-grid-item', collection: collection, grid_item_width: grid_item_width -%}
{% endunless %}

Code is sample only code is multiple times in code, Please make sure to update it every where.