Variant List Reference Metafield Not Outputting All References

I am using a list.variant_reference type metafield for my products. Lets say it’s named variant_products. When I access product.metafields.variant_products it shows me all 65 references I added. However, when I output product.metafields.variant_products.value
( {{ product.metafields.variant_products.value | json }} ) it only outputs the first 50 objects. Why is it doing this? This metafield type should be fine up to 128 references correct? I need to use value to access their ids.

Formal resource arrays in liquid have a natural cap of 50. So when you loop through collection.products product.variants shop.metaobjects.my_type.values etc you only get 50 iterations in your loop. The workaround, and this is not formally suggested by Shopify but we’ve all been doing it for like 10 years now…

You gotta do a little of this:

{%- liquid
  assign variant_products = product.metafields.custom.variant_products.value
  paginate variant_products by 1000
    for variant_product in variant_products
      # now do your thing.
    endfor
  endpaginate
-%}

Not sure what you want to do with this, but that’s that how I handle these situations. Also if it’s important, I am not sure if you can use the array filters on these paginated instances, but I’ve never tried it.

{% assign variant_products_ids = variant_products | map: 'id' %}
4 Likes

This worked perfectly. Thank you for your help Matthew!

1 Like