Calling meta fields from custom liquid

Topic summary

A developer is attempting to retrieve a custom metafield (custom.sync_varients) in Shopify using custom Liquid code without modifying the theme directly. The code works inconsistently—functioning on first click but failing when navigating to other products.

Key Issues Identified:

  • Missing .value property when accessing the metafield (should be product.metafields.custom.sync_varients.value)
  • The all_products object has a 20-use limit per page, which may cause intermittent failures
  • List-type metafields require loops or array access methods

Recommended Solutions:

  • Use a product reference metafield type instead, which returns a product object directly and eliminates the need for all_products
  • Verify all products have values entered in the metafield
  • Inspect the rendered output using browser developer tools to troubleshoot what’s actually being generated

The discussion remains open with troubleshooting suggestions provided but no confirmed resolution from the original poster.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

I’m trying to call a custom meta field which is a product type without having to add any custom code to the theme.

This is my code that I’ve put in the custom liquid within the theme.

I’ve set the custom.sync.varients for the products already but they don’t always work

{% assign product_rec_1 = all_products[product.metafields.custom.sync_varients] %}

{% assign product_rec_1_url = product_rec_1.url %}

{% assign image_url = 'https://t4.ftcdn.net/jpg/04/96/59/87/360_F_496598720_FfxVTaAu9ZEjlkxLHU0j68o4cnIGwa45.jpg'%}
{% assign link_url = 'https://your-link-url.com' %}

  

test

When I try to do this the link sometimes works but no always, it works on the first click but then when it goes to another product it doesnt work.

Can anyone help? Do I need to add custom code to the theme or can I avoid it?

Hi @developerrocket :waving_hand: You may need to use the .value property for the metafield i.e. product.metafields.custom.sync_varients**.value**

Otherwise just make sure each product has a value entered in that metafield

And this is for a single entry metafields, list-type metafields need a loop or other array access

Then inspect what’s actually being rendered with view source in the browser (ctrl+u), or the browsers devtools (ctrl+shift+i, or F12, or ctrl+shift+c)

Good Hunting

Also be aware that all_products has a limit of 20 uses for all liquid code on your page (https://shopify.dev/docs/api/liquid/objects/all_products) This may explain why sometimes it works and sometimes it does not.

if your metafield contains product handle, then you need to use all_products; but nowadays a better approach would be to have a product reference type metafield which will return a product object so there is no need for all_products.

1 Like