Hi, I’ve been working on implementing a new metaobject in my company’s Shopify store called Lessons. I’m able to access the lesson.title, lesson.description,etc. However, I cannot access the featured products. In my metaobject I set up a field called featured products and set it as a product data type (list option). I’ve tried so many different formats of dot notation to access the products for a lesson and nothing works. Anyone figured this out that can offer some advice?
{% for product in metaobject.featured_products %}
{{ product.title}}
{% endfor %}
outputs nothing.
Also tried accessing via the GIDs that are returned by looping through all_products and keeping the ones with matching IDs, but also displays nothing.
Hi @ginacostanzo
You need to call shop.metaobjects. Try the code below. You can read more about metaobjects here
{% assign metaobject_products = shop.metaobjects['featured_products '].values %}
{% for product in metaobject_products %}
{{ product.title }}
{% endfor %}
Please don’t forget to Like and Mark Solution to the post that helped you. Thanks!
Thanks for your reply. I’m calling metaobject directly because this is within a metaobject template. So my overall metaobject is called lessons and then within that one of the metafields is featured_products.
I created a metafield template so it will generate a page for every metaobject entry (every lesson), so that is why i’m writing just metaobject and not shop.metaobjects.
When I write metaobject.title it works.
If I write metaobject.featured_products I get back an array of gids, but haven’t been able to use that in any way. And if I try to loop through the featured_products to display properties of each product, it’s blank.
Okay update - I finally found a youtube video https://www.youtube.com/watch?v=eQHt2xil3Js that explains referencing products and objects in code and how the notation differs from something like simple text. Very informative video!