Field Reference Returning Incorrect Match for Selected Item
When working with any of the following field types, you might find that an item that was selected on the Custom Fields dashboard does not match the item that is displayed on the front end of your store:
- Product Reference (Legacy Version)
- Page Reference (Legacy Version)
- Blog Post Reference (Legacy Version)
- Collection Reference (Legacy Version)
- Blog Reference (Legacy Version)
NOTE: This issue does not affect newer Reference Fields that store values as GraphQL IDs.
This error is caused by a Liquid limitation while looping through the selected items on the theme template. For loops in Shopify Liquid are limited to 50 iterations per page and if for example, you have more than 50 blog posts on your store, you need to use the paginate tag to loop through the items that were selected in the Blog Post Reference field. This tag can be used with the following arrays in your theme template:
- all_products
- article.comments
- blog.articles
- collections
- collection.products
- customer.addresses
- customer.orders
- pages
- search.results
- collection_list settings
- product_list settings
Here is an example of how you can loop over blog posts on a site with more than 500 articles(It is recommended to set a maximum limit based on how many items the store would ever hold. In this example we have set it to 2000).
{% paginate blogs[article_blog_handle[0]].articles by 2000 %} {% for a in blogs[article_blog_handle[0]].articles %} {% if a.handle contains article_blog_handle[1] %} {% assign article = a %} {% break %} {% endif %} {% endfor %} {% endpaginate %}<br>