Extracting articles with specific IDs from a list of 1000 articles

Hello everyone,

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!

I think the most important part is

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 :wink:

1 Like

~ 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

2 Likes

Thank you for the advice!
I think you’re right. It seems like using Liquid alone will be a problem in the long run.

I used to be able to loop up to 1000 items with paginate and for combined, but I think a change in the June update limited it to 250?

I’ll look into using a web component with JavaScript. If I have any questions during the build, I’ll post again. Thank you so much!

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.

Did some tests on the side and I too, didn’t manage to get to 1000 sadly, only 250.

{% # Article pagination %}
{% liquid
  assign article_count = blog.articles_count
  assign article_list = blog.articles

  echo 'Total articles: ' | append: article_count | append: '<br><br>'

  echo '<br>Assigned variables:<br>'
  paginate article_list by article_count
    for article in article_list
      echo '- Article #' | append: forloop.index | append: ': ' | append: article.title | append: '<br>'
    endfor
  endpaginate

  echo '<br>Unassigned variables:<br>'
  paginate blog.articles by 1000
    for article in blog.articles
      echo '- Article #' | append: forloop.index | append: ': ' | append: article.title | append: '<br>'
    endfor
  endpaginate

  echo '<br>Offset pagination:<br>'
  paginate blog.articles by 1000, offset: 250
    for article in blog.articles
      echo '- Offset Article #' | append: forloop.index | append: ': ' | append: article.title | append: '<br>'
    endfor
  endpaginate
%}
  • First scenario only displays the first 50 articles
  • Second scenario displays the first 250 articles
  • Third scenario is equivalent to second scenario

Only way forward is to get help from Shopify but my advice would be to explore other options outside Liquid.

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.

Thanks again for all your help!

Hi @Kana_U ,

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.

Hi @Jason_Florence ,

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!

Hey @Kana_U ,

Thanks for the reply. So did the Storefront API allow for querying/searching more than 250 articles?