Personalized checkout and custom promotions with Shopify Scripts
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 %}
Solved! Go to the solution
This is an accepted solution.
Hi @begginer1231 ,
Yes, You can.
Please follow below steps:
{% 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.
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.
This is an accepted solution.
Hi @begginer1231 ,
Yes, You can.
Please follow below steps:
{% 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.
User | RANK |
---|---|
2 | |
2 | |
2 | |
2 | |
2 |
Transform this holiday season into a shopping spree. Plus, learn how to effortlessly open ...
By Jasonh Dec 8, 2023Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023