How can I access metaobject values in product metafields?

Topic summary

Core Issue:
Developers are struggling to access metaobject values stored in product metafields using Liquid, with initial attempts returning only GID reference URLs instead of actual field values.

Working Solutions:

  • For metafields containing metaobject lists:
{% assign items = product.metafields.custom.namespace.value %}
{% for item in items %}
  {{ item.field_name.value }}
{% endfor %}
  • For shop-level metaobjects (all entries):
{% assign icons = shop.metaobjects.icon.values %}
{% for icon in icons %}
  {{ icon.title }}
{% endfor %}

Key Distinctions:

  • Use product.metafields.custom.key.value when metafield references specific metaobjects selected per product
  • Use shop.metaobjects.type.values to access all metaobject entries globally
  • Access nested fields with .field_name.value syntax

Rich Text Handling:
For rich text metaobject fields, use:

  • metafield_text filter (strips formatting)
  • metafield_tag filter (preserves hyperlinks, lists)

Status:
Resolved through community collaboration. Multiple users confirmed working implementations. Documentation gaps noted as a recurring frustration during the feature’s early rollout.

Summarized with AI on October 30. AI used: claude-sonnet-4-5-20250929.

Hello,

My store has been given access to metaobjects, and so I’ve started using it and setup a few metaobjects that I want to use in the metafields for products and variants. But I don’t quite get how I can access the values of the meta object via the metafields?

I thought maybe something like this would make sense:

{% for metaobject in product.metafields.namespace.key %}
{{ metaobject.field.value }}
{% endfor %}

Appreciate the correct way to do this, and updating the Liquid API documentation would be very helpful.

Thanks.

Hey Rdaniel, what datatyp of metafield are you using?
Whats the output when you print {{ product.metafields.namespace.key }}?

Mabey your metafield value is a string? You can create an array with | split like so:

{% assign array = "value1,value2,value3" | split: "," %}
{% for value in array %}
  {{value}}
{% endfor %}

As described, I’m using metaobjects.

When printing {{ product.metafields.namespace.key }} I get the gid reference url.

Is there no one that can answer this? It would be poor to add such a nice way of storing information without the possibility to access the information in the frontend…?

They are a new feature, so everyone’s learning curve is high.

Thoroughly review the docs if you not simply using dynamic sources in theme settings.

Merchants start here

https://help.shopify.com/en/manual/custom-data/metaobjects

Devs

https://shopify.dev/docs/apps/custom-data/metaobjects

https://shopify.dev/api/liquid/objects/metaobject

Thanks,

I’ve read this documentation. But I can’t see how it gives information on how to access values from metaobjects that are defined in metafields in example of a product. Might be something I’ve overlooked though…

1 Like

Hi Rdaniel

Try to access all data with {{ product.metafields.namespace.values }} and then iterate through that

{% for metaobject in product.metafields.namespace.values %}
{{ metaobject.field }}
{{ metaobject.field.value }}
{% endfor %}

Maybe it is not clear with those abstract names so here is a small example.

Let’s say there is a meta object Icon with 2 fields Title and Image. To get those we iterate like

{% assign icons = shop.metaobjects.icon.values %}

        {% for icon in icons %}  
	        
	            

	            
	                {{ icon.title }}
	            
	        

        {% endfor %}

Try it out.

5 Likes

Using @LazaEAG example worked for a metaobject. But I wanted to use the metaobject as a database to store all the colour swatches for different products and select which ones I wanted to show on which product. The code above output EVERY colour swatch in the metaobject. So I made a metafield using the metaobject I had created as the content type.

That way for each product I can select which colour swatches from the metaobject that I want to display.

Modifying the code slightly for metafield:

{% assign swatches = product.metafields.custom.available_colours_swatches.value %}

                {% for swatch in swatches %}  
                  
                      
                      
                          {{ swatch.name.value }}
                      
                  

                {% endfor %}
5 Likes
{% assign myfields = product.metafields.custom.namespace.value %}

                {% for myfield in myfields %}  
                  

                      
                      
                          {{ myfield.name.value }}
                      
                  

                {% endfor %}
2 Likes

Hi @Phil_Houghton

First, thank you for sharing examples. And you are right, my example was some global case, I used it for one section with icons and as part of another object that has the same icons. Like you said for the product is slightly different.

1 Like

Thank YOU for pointing me in the right direction. Was frustrated by the lack of documentation and having no luck up until then executing what I needed to do :slightly_smiling_face:

1 Like

@Phil_Houghton Thank you for this. I didn’t have to iterate so I modified your code to make it work for me.

Here is my code for anyone reading this in the future:

{% assign foo = product.metafields.custom.backing.value %}

  
  

    {{foo.backing_title.value }}
  

Notes:

*This code works in Custom Liquid sections/blocks

*Replace backing with your metafield name

*Replace backing_img and backing_title with your metaobject’s field names

3 Likes

Hi all, I am not sure how this needs to work in other areas of shopify, such as collection page.

Basically I want to create a carousel that populates data from each entry inside of the metaobject created. I followed the above sets, but having 0 success. Below is the following code I have implemented.

{% assign pfilters = collection.metafields.custom.collection_filter.values %}

{% for pfilter in pfilters %}
{{ pfilters.collectiontitle.value }}
{% endfor %}

Hi @T_Chord22

You should try to debug and see where the issue appears.

So first check if {{ collection.metafields.custom.collection_filter.values | json }} is not empty. If it is try with {{ collection.metafields.custom.collection_filter.value | json }} so without “s” at the end.

Next step print {{ pfilter | json }} and also the try with {{ pfilters.collectiontitle }}

@LazaEAG thanks for the reply. I followed your steps above and it seems the only one that returns data is {{ collection.metafields.custom.collection_filter.value | json }}

This is what it returns: {“collectionimage”:“gid://shopify/MediaImage/33168175333688”,“collectiontitle”:“Kitchen”}

This returns: {{ collection.metafields.custom.collection_filter.values | json }} null
This returns: {{ pfilter | json }} null
This returns: {{ pfilters.collectiontitle }} nothing

@T_Chord22

Sorry now I am guessing a bit but if you see just one filter and you have entered more the try to print only

{{ collection.metafields.custom.collection_filter | json }}

And if that holds all filters then assign that to pfilters. Also I see mistake now here

{% for pfilter in pfilters %}
{{ pfilters.collectiontitle.value }}
{% endfor %}

{{ pfilters.collectiontitle.value }} is wrong, you have to target single filter so

{{ pfilter.collectiontitle.value }} or {{ pfilter.collectiontitle }}

Try a few things :slightly_smiling_face: and hope you find the right solution.

@LazaEAG Thanks lot for the answer.

@LazaEAG I have rich text input in the schema I was able to render the object.

on page display this object. but I want to render the HTML code. how I can do that?

{"type"=>"root", "children"=>[{"listType"=>"unordered", "type"=>"list", "children"=>[{"type"=>"list-item", "children"=>[{"type"=>"text", "value"=>"list"}]}, {"type"=>"list-item", "children"=>[{"type"=>"text", "value"=>"list 2"}]}, {"type"=>"list-item", "children"=>[{"type"=>"text", "value"=>"list 3"}]}, {"type"=>"list-item", "children"=>[{"type"=>"text", "value"=>""}]}]}]}
2 Likes

Hi guys, I’m having a similar issues and don’t understand what I’m doing wrong.

I have a customer metafield containing list of metaobjects. The metafield has namespace custom and key license_new and it references a metaobject of type license which has 2 fields:

  1. reference_product: reference to the product.
  2. license_files: a list of generic files.

I want to display the list of metaobjects, specifically a link to the reference_product and links to download the related license_files, in the customer account page. I’m attempting to do so using

{% assign licenses = customer.metafields.custom.license_new.value %}
      {% for license in licenses %}
        {{ license.reference_product.value }} 

      {% endfor %}

This doesn’t seem to work and I don’t understand why.

I tried a similar approach with a simpler metafiled of key licenses that only contains a list of generic files. If I try to display the files IDs by doing

{% assign licenses = customer.metafields.custom.licenses.value %}
      {% for license in licenses %}
        {{ license.id }} 

      {% endfor %}

everything works as expected.

Can anyone see what I’m doing wrong? Thank you :slightly_smiling_face:

Hi, I’m having an issue with this code where it’s getting the data from all products rather than the current product.

I’ve updated my code to the below:

{% assign icons = shop.metaobjects.features.values %}

{% for icon in icons %}

{{ icon.one }}
{% endfor %}

I’ve also tried this but it doesn’t work:

{% assign icons = shop.metaobjects.features.values | where: ‘product_id’, product.id %}

{% for icon in icons %}

{{ icon.one }}
{% endfor %}