Can I filter collections with Metafields?

Solved
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
Highlighted

Success.

Shopify Partner
1838 174 626

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
Highlighted
Shopify Partner
1353 22 218

:) 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
Highlighted
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
Highlighted
New Member
6 0 0

Hi Mircea

0 Likes
Highlighted
Shopify Partner
1353 22 218

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
2 Likes
Highlighted
New Member
6 0 0

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

0 Likes
Highlighted
New Member
2 0 2

@PaulS wrote:

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


Paul, did you ever figure out a solution to this issue?

0 Likes
Highlighted
New Member
6 0 0

Hi jrennaker, searched everywhere but no luck, seems to be a huge Shopify limitation for complicated products/businesses like ours. We have more than 5000 SKUs so the workaround for 'under 100 products' won't work, so sticking with Magento.

0 Likes
Highlighted
New Member
6 0 0

Hi jrennaker,

Just saw something that may be helpful for you. Seems like these guys have recently added the ability to Search & Filter via Metafields:

https://apps.shopify.com/searchanise

I haven't tested it myself, but do let me know how you go if you happen to test this out.

Regards

0 Likes