Shopify Access Metaobjects With Liquid

February 15th, 2023





Shopify recently released their Shopify Editions 2023, highlighting new features and updates to the platform.

One of these new features is called metaobjects.

Think of metaobjects like any other object you can access with liquid in Shopify, such as a product, blog post, page, or category.

Metaobjects are similar to these but allow the user to create the fields.

The documentation is surprisingly slim on how to actually use these, so I’ve collected what I’ve found so far and put it here.

Begin by adding a new metaobject definition. Metaobject definitions are added in the Admin panel under settings->custom data->metaobjects.

From here fill out the name and fields you want for this object.

Once you are ready to add some metaobject entries, head over to admin->content->metaobjects.

Click on “Add entry” and select the newly created definition.

Fill out the fields with data and hit save.

You can now access this data anywhere you use liquid using square bracket notation or dot notation:

{{ shop.metaobjects.customer_reviews.joeybab3-3.author }}
{{ shop.metaobjects['customer_reviews']['joeybab3-3']['author'] }}
# Joeybab3
{{ shop.metaobjects.customer_reviews.joeybab3-3.date }}
{{ shop.metaobjects['customer_reviews']['joeybab3-3']['date'] }}
# 2022-02-15
{{ shop.metaobjects.customer_reviews.joeybab3-3.product }}
{{ shop.metaobjects['customer_reviews']['joeybab3-3']['product'] }}
# Microtransactions
{{ shop.metaobjects.customer_reviews.joeybab3-3.review_snippet }}
{{ shop.metaobjects['customer_reviews']['joeybab3-3']['review_snippet']}}
# This was the worst product I've ever used and I hated it.

Comments

4 thoughts on "Shopify Access Metaobjects With Liquid"

  1. Joe says:

    Hi, could you add a snippet to loop over all the metaobjets of a given definition? e.g. iterating over all customer_reviews of your example.

  2. Ahmad Naeem says:

    Hello mate
    Thanks for sharing.

    After alot of struggle, I find your article and solve my problem.
    Thanks

  3. JM says:

    Thanks a lot for the tutorial, much needed as Shopify does not provide much .liquid support for this new feature.
    However, after lots of testing, I feel your proposal fits with the shopify documentation suggestion but does not really work. Did you and implemented it on a shopify store yet?
    Thanks a lot!!

    1. joeybab3 says:

      I have played around with it in a dev environment but have not yet used it in a live production environment, mostly because I do not yet have a usecase for it.

Leave a Reply

Your email address will not be published. Required fields are marked *