Re: metaObject values then "List of values"

How can I extract values from a selected metaObject list?

Darius90
Shopify Partner
44 1 11

Hi everyone,

 

it looks so simple thing but can't get the values of the metaobject when it is selected "List of values".

 

I thought I have to once again iterate it. But it returns nothing. It is really frustrating debugging when not getting any errors. 

 

 

{% assign myfields = product.metafields.sp_custom.size_chart_metaobjects.value %}

{{ myfields }}
// it return MetaobjectDrop

{% for m in myfields.sizes %}  
    {{m.value}} //nothing works
    {{m[0].value}} //nothing works
{% endfor %}

or

{% for m in myfields %}  
  {% for s in myfields.sizes %} 
    {{ s }} //nothing works
    {{ s.value }} //nothing works
    {{ s[0].value }} //nothing works
  {% endfor %}
{% endfor %}

 

 

 

this article doesn't help much... https://community.shopify.com/c/technical-q-a/metaobject-values-in-metafields/m-p/1939164

 

Darius90_0-1681311174097.png

Darius90_1-1681311188715.png

 

...
Replies 10 (10)

nima_riahi
Shopify Partner
4 0 0

Hi Darius,

 

Add this to your liquid and send here what you get in your browser console:

<script>{{ myfields | json }}</script>

 

josu24
Shopify Partner
11 0 0

I have the same issue. Really annoying. You get: "error: json not allowed for this object"
It's an array. ["S", "M", "L"]

nima_riahi
Shopify Partner
4 0 0

@josu24 what about the result of this one?

<script>{{ myfields | json }}</script>
nima_riahi
Shopify Partner
4 0 0

@josu24 what about the result of this one?

<script>{{ myfields.value | json }}</script>

WildFoodOutdoor
Tourist
3 0 1

I am having this same issue... can't figure out how to access the list of values correctly. ANy progress?

nima_riahi
Shopify Partner
4 0 0

Give more information on what are you trying to access in your code send that part of your code here!

Massy
Shopify Partner
1 0 3

I did debugging metaobject when it is selected "List of values" below.

It should shows key and value set for size_chart_metaobjects metafield.

product.metafields.sp_custom.size_chart_metaobjects.value | json

 

So, product's meta fields value can be referred by this code.

product.metafields.sp_custom.size_chart_metaobjects.value['size_chart_metaobjects']

 

Hope it works for everyone who has been stuck on this issue.

FerhatCengiz
Shopify Partner
9 1 2

And also, a quick addition;

 

If you'd like to access a spesific type in this: 

 

product.metafields.sp_custom.size_chart_metaobjects.value['size_chart_metaobjects']

 

you need to use a forloop to access it's spesific values like the following:

 

{% for prod in product.metafields.sp_custom.size_chart_metaobjects.value
%}
{{ prod.title }}
{% endfor %}​

 

themoshiur
Shopify Partner
1 0 0

Thanks a lot, that's also helped me, even the Shopify chatbot also gave the error code, it took my full night.

hakunamase
Tourist
3 0 1

Amazing! Thank you so much!!! Been stuck on this problem for such a long time!