Can I filter collections with Metafields?

Solved
Highlighted
Excursionist
41 0 6

Hi,

 

Is there a way to filter collections with product metafields?

 

For example:

shop.myshopify.com/collections/shirts/?metafields.attributes.size=large 

Should return all products in the the shirts collection that have this metafield:

 

  • namespace: attribute
  • key: size
  • value: large

 

If yes, what is the correct URL syntax to filter collections with product metafields?

If you can't do it this way, what would be the workaround to filter collections with metafields?

 

Thanks in advance,

Martin

 

Martin Schwartz - Coding your dream to life - iconstudiosny.com
0 Likes

Success.

Shopify Partner
1843 171 542

Hello Martin,

 

You prefer the good news or bad news?

 

Bad news is you cannot filter collections by custom fields beyond those documented by Shopify - metafields aren't supported for filtering and there is no workaround unless you're good with Liquid and Javascript.

 

Good news is you can achieve it as long as you have less than 1000 products (won't be able to work around that limit unless you switch to Storefront API but that's a whole different story) and are GOOD at Liquid and Javascript. In that case you'd want to look at this thread here and ask the expert himself @Mircea_Piturca how exactly it's done.

 

Hope this helps!

I turn coffee in to code - since 1998
0 Likes
Shopify Partner
1361 21 194

:) Hardly an expert but thanks @KarlOffenberger 

 

Forgot about that demo...

But it's a good place to start.

 

You will need to get the products metafields data.

Alternative templates with {% layout none %} can be used to generate a the data you want.

Have a look at https://filter-3.myshopify.com/collections/guitar?view=filter-json

It will output a JSON string containing the metefields data.

 

The filtering will happen in JS, based on the meta you can display the products that match the user selection.

 

I hope to have time and write a small tutorial on that.

Hope it helps.

https://sections.design tips, tricks & Shopify sections
1 Like
Shopify Partner
15 0 0

@Mircea_Piturca  @KarlOffenberger 

Hi there Mircea and Karl,  for the 1000 limit, is this limit only on a collection of products? or on the whole product list? 

 

Please let me know. 

 

—K

 

0 Likes
New Member
4 0 0

Hi Mircea

0 Likes
Shopify Partner
1361 21 194

Hi Paul,

I am sorry but I am not taking new projects at this time.

 

I want at some point to publish an open source code, however this is quite tricky as most stores have custom setups.

Thanks

https://sections.design tips, tricks & Shopify sections
0 Likes
New Member
4 0 0

That's all good, thank you Mircea :-)

0 Likes