Solved

Filtering collections by metafields using 'where'

begginer1231
Shopify Partner
19 0 1

Hi,

Is there anyway to filter collections with metafields?

https://community.shopify.com/c/shopify-design/filtering-collection-by-metafields-in-theme/m-p/17538...

************************************************************************************

 

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 %}

************************************************************************************

Accepted Solution (1)

James_FoxEcom
Shopify Partner
75 14 18

This is an accepted solution.

Please try this code instead

{% assign vendors_collection = collections | where "collection.metafields.custom.is_vendor.value, true %}
Find my answer helpful? Give it a like 🙂
Try Foxify now - #1 Conversion-focused page builder.
Proudly made by FoxEcom.com - Smart & hyperefficient front-end solutions for SMBs. Impact sales, costs, and revenue all at once.

View solution in original post

Replies 2 (2)

James_FoxEcom
Shopify Partner
75 14 18

This is an accepted solution.

Please try this code instead

{% assign vendors_collection = collections | where "collection.metafields.custom.is_vendor.value, true %}
Find my answer helpful? Give it a like 🙂
Try Foxify now - #1 Conversion-focused page builder.
Proudly made by FoxEcom.com - Smart & hyperefficient front-end solutions for SMBs. Impact sales, costs, and revenue all at once.

Miriam_Solovey
Shopify Partner
26 0 2

Hi @begginer1231, this is Miriam from Kimonix app. You don’t have to work hard with implementing code for this - our app can help you with a click of a button 🙂

Simply activate the sync of metafields and you can start using them as filters. Here’s how it looks in the app:

 

Activate the sync -

Miriam_Solovey_0-1706456420716.png

 

Start using them as filters -

Miriam_Solovey_1-1706456420716.png

 

Read our article on this 👈

We are a plug-and-play solution (we are not touching your code) so feel free to try the app.

Hope this helps and let me know if you have any questions! 🤗