Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
Is there anyway to filter collections with metafields?
************************************************************************************
We have some metafields on our collections and we want to filter the collection by the metafield, to display only collections where the metafield: is_vendor is set to true.
For example:
{% assign vendors_collection = collections | where "collection.metafields.custom.is_vendor, true %}
This doesn't seem to work.
We are currently using a conditional operator to only show the vendors but I assume their is a better way of doing this.
Here is the code we currently have to display only vendors:
{% assign vendors_collection = collections %} {% for collection in vendors_collection %} {% if collection.metafields.custom.is_vendor == true %} {% render 'custom-collection-card' %} {% endif %} {% endfor %}
************************************************************************************
Solved! Go to the solution
This is an accepted solution.
Please try this code instead
{% assign vendors_collection = collections | where "collection.metafields.custom.is_vendor.value, true %}
This is an accepted solution.
Please try this code instead
{% assign vendors_collection = collections | where "collection.metafields.custom.is_vendor.value, true %}
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024