Skip to content

Shopify Dude Fix

Shopify Product Metafield Shows a GID Instead of Content? Dereference the Value

Render referenced products and metaobjects correctly in Liquid instead of displaying their stored identifiers.

Quick answer: Use the typed metafield’s value and access the referenced object’s fields.
On this page

Why this happens

Reference metafields store relationships, not presentation-ready text. Treating the metafield as a plain string loses the benefit of the typed object.

Implementation

Check the metafield definition in Settings > Custom data. Confirm whether it is a single reference or a list. Use value to obtain the referenced object or iterate over the referenced objects. Guard against empty values and confirm storefront access for referenced metaobjects.

Example

{% assign related = product.metafields.custom.related_product.value %}
{% if related != blank %}
  <a href="{{ related.url }}">{{ related.title | escape }}</a>
{% endif %}

For a list of product references, loop over the metafield’s value rather than splitting the stored representation. For metaobject fields, inspect their types and dereference those fields as appropriate.

Common misunderstanding: A reference ID is not a storefront URL, and a list reference is not a comma-separated string.
How to test this:

  1. Test an empty reference, one populated reference and a list reference
  2. remove a referenced entry
  3. check storefront visibility and translated content
  4. verify the rendered link.
Sources and further reading: Shopify reference ยท Shopify documentation