Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I would like to filter an array of products using values from the "properties" field. Specifically so in the cart with line_items.
I am currently trying to use the "where" filter, to only include products with the property of "group-id". Ideally, this would be as easy as:
{% assign filtered_items = items | where: 'properties.group-id' %}
But from trying this, and searching around in the documentation and online, it doesn't look like others were able to get it to work.
I understand this can be implemented using a for loop with conditional checks, but I am curious about this method.
Solved! Go to the solution
This is an accepted solution.
I wasn't able to use the where filter as I was hoping, but ended up solving the issue anyway.
In my use case, I needed to create sub-arrays based on a common property. And this common property always showed up contiguously across items in the original array. This made the situation a little easier. I just iterated through the original array, kept track of the relevant indices, and took slices of it using slice to create the sub-arrays.
This is an accepted solution.
I wasn't able to use the where filter as I was hoping, but ended up solving the issue anyway.
In my use case, I needed to create sub-arrays based on a common property. And this common property always showed up contiguously across items in the original array. This made the situation a little easier. I just iterated through the original array, kept track of the relevant indices, and took slices of it using slice to create the sub-arrays.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025