I’m trying to extract articles by specific IDs in my Liquid templates. The behavior seems to have changed with a recent update, and I’m looking for a solution.
The Problem
Previously, I could efficiently extract all articles from a large list of about 1000 items by setting a generous page size in paginate. This method bypassed the standard for loop’s 50-item limit.
However, the per-page limit for paginate now seems to be capped at 250 items. This means my old code only searches the first 250 articles, and any items beyond that are not found. The total number of articles I need to search through is around 1000. And many more to come.
My Question
Given the current paginate limit of 250 items per page, what’s the best practice for extracting articles by ID from a list of this size?
Is it possible to solve this using Liquid only?
Any insights would be greatly appreciated. Thanks!
Using only Liquid, you will sooner than later be confronted with the issue. I would advise to design a web-component that will provide the desired behavior. For example, you could keep using your paginate setup, having 250 articles IDs via Liquid and the web-component Javascript would fetch the other articles.
Without more context, that’s the most I can tell you but Liquid will only get you so far if you go beyond 1000 articles.
You can check this post and see if you can translate the code to use articles
~ No, because what’s the actual goal.
If your trying to do dynamic search get a dedicated search app.
If your just trying to get some index or other property then use flow app + metafields + liquid to achieve it.
But again without a clear goal, https://xyproblem.info/, this is waxing poetic for workarounds
Thank you for your reply. That makes a lot of sense.
My actual goal is to show related articles on a product page.
Each product has a metafield called related_article_ids. The metafield type is a single line of text, and I input several IDs into it, separated by commas. I then have a section on the product page that renders the articles specified by this product metafield.
The following is a modified version of the Liquid code I used to use:
I’d get the article handle first, and then render the article’s information using that handle.
{% liquid
assign article_ids_array = related_article_ids | split: ','
assign article_handles = ''
for article_id in article_ids_array
assign article_id_number = article_id | plus: 0
assign found_handles = ''
paginate main_blog.articles by 1000
for article in main_blog.articles
if article_id_number == article.id
assign article_handles = article_handles | append: article.handle | append: ","
endif
endfor
endpaginate
endfor
%}
This code used to be able to loop through all the articles in the blog and get/render the specific articles I needed.
However, it seems a recent Liquid update has limited the loop to only 250 articles. I confirmed this by checking the forloop.index. As a result, it can no longer find and render the articles I want if they are beyond that limit.
I would be grateful if you could let me know if you are aware of any optimal solution for this.
Thank you so much for taking the time to test the code on your end.
It’s unfortunate that the limit is indeed 250 articles, but your confirmation is very helpful.
I agree that the best path forward is to move beyond Liquid. I will look into using the Storefront API to handle it.
Did you ever find a solution to fetching beyond 250? I have a similar setup to fetch articles related to a “parent” article, through custom metafields, but can’t get around the 250 limit.
Yes, we ended up deciding to use the Storefront API.
I also reached out to Shopify support about this, and they confirmed the limit for paginate and for loop is now 250. They mentioned the change was made sometime in June.
They also did confirm that other merchants are facing the same issue with this limit.
I’m not sure of the specifics of your situation, but based on my experience, I would recommend looking into the Storefront API instead of trying to get around the Liquid limitation.
Hope this helps, and good luck finding a solution!