A user encountered an issue accessing metafield data within a Custom Liquid section on a Shopify product page. When attempting to retrieve Instructor metafield information (name, bio, job_title, headshot), they only received a metaobject reference ID instead of the actual data.
Root Cause:
Shopify metaobjects return references by default, not the actual field values. The original code accessed product.metafields.custom.instructor directly, which only returned the GID reference.
Solution:
Access the metaobject using .value to retrieve actual data:
I’m having trouble accessing the data in a metafield object from a product page.
I can get at the data from the other sections by connecting data sources to different fields, but I can’t access the data in the metafield within a “Custom Liquid” section for some reason. I’m trying to keep different Instructors in the metafield and I’m attaching them to classes that we are listing as products on our page.
I have a metafield called Instructor, within the instructor metafield, I have name, bio, job_title, headshot, etc…
Am I doing something wrong? Support tried to tell me I should create my own “Custom Liquid Section” and do what I’m trying to do. But I haven’t gotten a straight answer on whether that is true or not. I’m not clear on what is going wrong.
You’re actually on the right track, but Shopify’s metafields for metaobjects behave a bit differently when accessed in Liquid. The issue is that you’re retrieving a metaobject reference instead of the actual metafield values.
### How to Fix It?
To properly access your Instructor metafield data, you need to fetch the referenced metaobject fields.
Why Does This Work?- product.metafields.custom.instructor returns a metaobject reference, not the actual data.
product.metafields.custom.instructor.value retrieves the actual metaobject, allowing you to access its fields directly.
### Debugging Tip
If you’re still getting a reference instead of data, try logging just the .value:
This should now show the full object instead of just the reference ID.
### Is Shopify Support Right About Creating a Custom Section?
Not necessarily. You don’t need to create a separate section just to access metafields. Using a Custom Liquid block within an existing section should work fine as long as you’re using .value correctly.
Since you’re working with product metafields, it’s also a good idea to ensure your product pages are fully optimized for search engines. Structured data, well-crafted SEO titles, and detailed descriptions can make a big difference in visibility. If you’re looking for a tool that can help audit and bulk-optimize your Shopify product SEO, there are apps like SEOPro that streamline the process.