Shopify Metafields: How to Model Product Data That Scales
Shopify metafields explained by an operator: definitions vs raw metafields, which type to pick, Liquid and GraphQL access, real limits, and common mistakes.
The short answer
Shopify metafields are custom fields you attach to products, variants, collections, customers, orders, pages, the shop itself and more. You create a definition under Settings > Custom data, which fixes the namespace, key, type and validation, then fill in values per resource and render them with Liquid or read them through the Admin and Storefront GraphQL APIs. If a product attribute matters to filtering, a feed or a template, it belongs in a metafield, not in the description HTML and not in tags.
That is the mechanics. The rest of this post is the part that decides whether metafields make a catalog easier to run or turn into a second mess: picking the right owner and type, naming, and knowing where the limits are.
Definitions first, always
A metafield can exist without a definition. Apps and old imports write them all the time. In the admin, under Settings > Custom data, each resource has a list of metafields without a definition. These have a namespace, key, type and value, but no validation, no proper editing UI for staff, and they cannot be used as theme editor dynamic sources or as Search & Discovery filters.
A definition is what turns a metafield into a real field. It gives you:
- An input in the product (or variant, or collection) editor that staff can fill without touching code.
- Validation: minimum and maximum, character limits, regular expressions, preset choices, allowed reference types.
- Storefront access that you can switch on or off.
- Eligibility for filters, smart collection conditions, dynamic sources and sales channel mapping.
When I inherit a store, one of the first things I do is list the metafields without a definition and decide, key by key, whether to adopt or retire each one. Adopting means adding a definition with the same namespace and key. Shopify then flags the existing values that fail the new validation rules, and you fix them before relying on the field.
Choosing the owner: product, variant or something else
The most expensive metafield mistake is putting data on the wrong object, because moving it later is a migration.
- Product for anything true of every variant: material, care instructions, country of origin, a size chart reference, a spec block.
- Variant for anything that changes per variant: a per-size weight or dimension, a per-colour lead time, a supplier code, a variant-specific download. The rendering side is its own topic, covered in Shopify variant metafields.
- Collection for landing content: an intro below the grid, a hero image, a reference to an FAQ.
- Shop for global values the theme needs everywhere: a free shipping threshold, a support phone number, a banner string.
- Customer and order for operational data: a trade tier, a gift note, an ERP reference.
If the value is really a reusable thing with several fields of its own (a fabric with care rules, a designer with a bio and a photo, a size chart), it is not a metafield value. It is a metaobject, and the product holds a reference to it. See Shopify metaobjects for that pattern.
If you sell in a category that Shopify's Standard Product Taxonomy covers, check what it already gives you before you create your own colour or size fields. That is Shopify category metafields.
Choosing the type
Shopify's type list is long. These are the ones I actually use:
single_line_text_field, usually with preset choices. Presets turn free text into a controlled vocabulary, which is what you want for anything that will be filtered.multi_line_text_fieldandrich_text_fieldfor copy. Rich text keeps bold, lists and links without letting staff paste raw HTML.number_integer,number_decimal, and the measurement types (weight,dimension,volume), which store a value and a unit together.booleanfor flags such as "final sale" or "ships separately."dateanddate_timefor launch dates and restock estimates.file_referencefor PDFs and images that belong to one product.product_reference,variant_reference,collection_reference,metaobject_reference, and theirlist.versions.jsononly when nothing else fits. It has no friendly admin input, cannot be filtered, and staff will break it.
Two rules I hold to. Anything a customer might filter on gets a filterable type: text with presets, a number, a boolean, or a metaobject reference. And anything with a unit gets a measurement type, not a text field with "12 in" typed into it.
Namespace and key conventions
Merchant definitions default to the custom namespace, which is fine. The key is what you will type in Liquid for years, so make it boring and specific: custom.material, custom.care_instructions, custom.size_chart. Avoid keys that describe presentation (custom.tab_2_text), because the template will change and the data will not.
Do not write into namespaces that belong to apps or channels. The Google & YouTube channel, for example, stores its product fields under mm-google-shopping. Reading those values is fine. Writing them from your own script means two systems own one value.
Rendering metafields in Liquid
On an Online Store 2.0 theme, most single metafields can be connected to section and block settings through the dynamic source icon in the theme editor, with no code. When you need code, the pattern is:
{%- assign material = product.metafields.custom.material -%}
{%- if material != blank -%}
<p class="product-material">{{ material.value }}</p>
{%- endif -%}
The .value matters. For references, it returns the referenced object, so a metaobject-backed size chart looks like this:
{%- assign chart = product.metafields.custom.size_chart.value -%}
{%- if chart -%}
<h3>{{ chart.title.value }}</h3>
{{ chart.measurements | metafield_tag }}
{%- endif -%}
For rich text and measurement types, the metafield_tag and metafield_text filters render sensible HTML or plain text, so you are not hand-formatting units. For list references, a plain for loop returns only the first 50 items. Use paginate if a list can grow past that.
Writing metafields with the API
From an app or script, metafieldsSet is the mutation to use. It creates or updates, and takes up to 25 metafields per request.
mutation SetMaterial($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields { id namespace key value }
userErrors { field message code }
}
}
{
"metafields": [
{
"ownerId": "gid://shopify/Product/1234567890",
"namespace": "custom",
"key": "material",
"type": "single_line_text_field",
"value": "Linen"
}
]
}
Always read userErrors. A value that fails the definition's validation does not throw an HTTP error. It comes back in that array and nothing is written, which is how scripts "succeed" while changing nothing.
For a catalog-wide backfill, do not loop metafieldsSet from a laptop. Use a bulk operation or a spreadsheet tool. I do most metafield backfills with Matrixify, because the export before the import is my rollback file and the import gives me a per-row result.
The limits that matter
From Shopify's current developer documentation:
- Up to 256 merchant-created definitions per resource type, and separately up to 256 per installed app. Standard definitions do not count.
- Up to 50 pinned definitions per resource type.
- Most types cap a single value at 64 KB,
jsonat 128 KB for most apps, under a 2 MB global ceiling. - List types hold up to 128 items. Metaobject reference lists hold up to 1,024.
- Up to 128 definitions can be used as smart collection conditions.
Few stores reach the definition cap. The limit people actually hit is the 50-item Liquid loop on a list reference, usually a "complete the look" list that a merchandiser kept growing.
Mistakes I keep cleaning up
Specs pasted into the description. A spec table inside the description HTML cannot be filtered, cannot feed a channel, and breaks the moment someone edits it in the rich text editor. Move it into metafields once and the template renders it consistently on every product.
Tags used as data. material:linen as a tag is a metafield pretending to be a tag. Tags have no type, no validation and no owner. They are fine for internal workflow flags and poor as product attributes.
One field per language. custom.description_fr is not how translation works on Shopify. Metafield values can be translated with Shopify's translation tools, so keep one field and translate it.
No owner for the data. A metafield that marketing, a PIM sync and a Flow all write to will be wrong within a month. Decide which system is the source of truth for each key and make everything else read-only.
A starter checklist
- List every product and variant definition under Settings > Custom data, plus every metafield without a definition.
- For each attribute customers filter or compare on, confirm it has a definition with a filterable type.
- Pin the ten fields staff edit most so they sit at the top of the product editor.
- Search the theme code for
metafields.and confirm every key it reads still exists. - Write down the source of truth per key: admin, PIM, app or import.
If you would rather have someone design the structure and run the backfill on a live catalog, that is a large part of what I do as a Shopify developer for hire.
I design metafield structures and run catalog-wide backfills on production stores; see [Shopify expert development](/shopify-expert) and [Matrixify catalog operations](/matrixify-expert). Related: [Shopify Metaobjects: When to Use Them and How to Build One](/blog/shopify-metaobjects), [Shopify CSV Import: Where the Native Importer Breaks](/blog/shopify-csv-import-bulk-product-upload).
Direct: [WhatsApp +55 11 98851-2788](https://wa.me/5511988512788) · [contact@matheusabrahao.com](mailto:contact@matheusabrahao.com)
Need a senior engineer who thinks like an operator?
I take on a small number of Shopify operations and senior engineering engagements each quarter. If your store needs catalog hygiene, technical SEO, performance or marketing automation done right, let’s talk.
Continue reading
Shopify Canonical URLs: The Duplicate Content Trap in Collections and Filters
How Shopify canonical URLs actually work, why collection-scoped product URLs and filter parameters multiply your index, and the theme-level fixes that hold.
Shopify Schema Markup: What Actually Earns Rich Results Now
FAQ rich results are gone. What still earns them: the structured_data Liquid filter, Product vs ProductGroup, and the required merchant listing fields.