pagination - Liquid apply filter to pagnation and for loop in shopify
I'm trying to render & paginate collections that have a metafield "is_artist" set true. However I can't seem to get the filter to work, I'm new to shopify/liquid and used to Wordpress so maybe I'm overlooking something.
What happens with my current code is that the pagination works, but it'll render pages for ALL the collections, not just the ones with the metafield set to true. The if statement works so some pages will show collection titles but others are just empty. I'm guessing the "where" in my pagination is not working properly, but no clue how to do this otherwise in Liquid.
Maybe this is not the way at all to do this, but here is my code:
{% paginate collections | where: collection.metafields.custom.is_artist = true by 10 -%}
{%- for collection in collections %}
{% if collection.metafields.custom.is_artist == true %}
<h2>{{ collection.title }}</h2>
{%- endif -%}
{% endfor %}
{{ paginate | default_pagination: next: 'Older', previous: 'Newer' }}
{% endpaginate %}
Example outputs:
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.