The metafield object

Metafields make it possible to store additional information for articles, blogs, collections, customers, orders, pages, products, the shop, and variants. You can access the metafield object through the metafields attribute of these resources.

Metafields support multiple data types, which determine the kind of information that's stored in the metafield object. You can also apply Liquid metafield filters to this object in order to output metafield information in a standard format.

The metafield object has the following attributes:

metafield.type

Returns the metafield type.

metafield.value

Returns the metafield value.

The following outlines the value format for each metafield type:

Type Returned format
  • single_line_text_field
  • multi_line_text_field
A string
product_reference A product object
variant_reference A variant object
page_reference A page object
file_reference A generic_file object
  • number_integer
  • number_decimal
A number
  • date
  • date_time
A date object
url_reference A url string
json A JSON string
boolean A boolean
color A color object
  • weight
  • volume
  • dimension
A measurement object
rating A rating object

Access metafields

The access path for metafields consists of two layers:

  • namespace - A grouping of metafields to prevent conflicts.
  • key - The metafield name.

Given this, you can access the metafield object with the following syntax:

For example, you might have the following metafield added to a product:

Type Namespace Key Data
single_line_text_field instructions wash "Cold"

Using this metafield information, the following input generates the following output:

Direct access

Metafields must be accessed directly using their associated key. For example, you can't loop over a namespace to get each individual metafield:

Deprecated metafields

Deprecated metafields are older metafield types with limited functionality. The following metafield types are deprecated:

  • json_string
  • number
  • string

These metafield types don't return the same metafield object attributes mentioned in the previous section. Instead, they return the metafield value directly.

The following outlines the returned value type for each deprecated metafield type:

Metafield type Returned value type
integer An integer
json_string A JSON object
string A string

For example, you might have the following metafield added to a product:

Type Namespace Key Data
string instructions wash "Cold"

Using this metafield information, the following input generates the following output: