Metaobject Input With Variant Data Type Only Returns GID

Topic summary

A developer encountered an issue where a Variant input field within a metaobject definition only returned a GID (global identifier) instead of full variant data, unlike a Product input field which returned complete information.

Root Cause:
The problem occurred because the selected variant belonged to an archived product. Archived variants return only their GID through Liquid, with all other properties appearing blank.

Solution:
Access variant data from metaobjects using the .value key:

{% for variant in product.metafields.custom.variants.value %}
  {{ variant.variant.value.id }}
{% endfor %}

Key Takeaway:
When working with Variant-type metaobject fields, ensure the referenced variants belong to active (non-archived) products to retrieve full variant properties beyond the GID.

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

Hello!

I’m attempting to get variant information from an input field within a metaobject definition (Note: not a metafield definition). The data type for the input is Variant which presents a variant picker to the user. Everything up to that point works as expected. I also have the same setup for a Product input field. What’s odd to me is that I can easily access all of the information for the Product value that gets returned with code like this:

{%- for entry in shop.metaobjects.store_content_schedule['2024-04-10']['cart_drawer_content'].value -%}
  {%- if entry.product != blank -%}
     {%- assign content_media = entry.product.value.featured_image -%}
  {%- endif -%}

  {%- assign img_width = 240 -%}
  {%- assign content_media_src=content_media | image_url: width: img_width -%}
  {%- assign content_media_alt_text = content_media.alt -%}

  
{%- endfor -%}

As expected, this consistently yields an image with all of this information filled in. If I try to do the same thing with the Variant input field however, everything is blank. The only thing I’ve been able to successfully return from the Variant input was a gid by doing something like this:

{%- if entry.variant != blank -%}
  {{ entry.variant }}
{%- endif -%}

All of the sane and wacky attempts below return absolutely nothing:

{%- if entry.variant != blank -%}
  {{ entry.variant.id  }}
  {{ entry.variant.value }}
  {{ entry.variant.value.id }}
  {{ entry.variant.values.id }}
  {{ entry.variant.id.value }}
  {{ entry.variant.id.values }}
  {{ entry.variant.value.id.value }}
  {{ entry.variant.values.id.value }}
  {{ entry.variant.value.id.values }}
  {{ entry.variant.values.id.values }}
  {{ entry.variant.value.id.values }}
  {{ entry.variant.values.id.values }}
  {{ entry.variant.value.id.values }}
  {{ entry.variant.values.id.values }}
{%- endif -%}

I’ve checked the docs (metaobject, data types, variant object) and can’t seem to find an explanation as to why this might be. Does the Variant input also need a Product input for some reason? Meaning do I first need to grab a product using the Product input field and then using that information use the Variant input field to target that specific variant within the Product returned from the Product input?

Any help that can be offered would be greatly appreciated!

1 Like

Soooooo egg on my face. It turns out I was seeing this behavior because I hadn’t noticed that the variant I was randomly selecting in during my testing belonged to a product that had actually been archived. So, as one might expect, if the variant you’re attempting to get via liquid is archived it’ll return the gid but nothing else.

Thanks for your reply. I already tried similar things, and your reply helps me and saves a lot of time and effort. I want to add an extra suggestion. use the value key for accessing the variant data.

{% for variant in product.metafields.custom.variants.value %}
{
  "actual_variant": {{ variant.variant.value.id }}
}
{% endfor %}