I’m exploring the new metaobjects feature and it’s opened up a world of flexibility! However I have a question for the community to see if anyone knows if the following is possible…
When viewing a metaobject entry in the shopify admin there is a section called “Referenced by” that lists all products (and other entries) that reference this metaobject in their own metafields, and I’m wondering if it’s possible to access these back referenced products via code in the theme files?
My use case is as follows:
Create a metaobject definition called “Product Group”
Create a Product Group entry called Group 1
Create a metafield on products that references the Product Group metaobject
Assign Group 1 to Product X’s metafield, repeat this for Products Y and Z
Access Products Y and Z via Group 1’s back references from Product X
This is what I imagine the code might look like:
assign group = product.metafields.custom.product_group.value
assign group_products = group.referenced_by !!this is the part I'm interested in!!
Does anyone know if there is a way to do this? For the time being I’ve decided to add an extra metafield to the metaobject called products and I manually add the products so that they can be accessed directly via bundle.products.value, however this adds a bit of duplicated work that I’d ideally like to avoid, and since the admin seems to be able to display these back references I’m hoping the code can as well.
I’m also really interested in this. I’ve tried a few methods to try and achieve this through some complex forloops but even if I found a solution it would be highly inefficient and would probably slow down the page rendering a lot. So to be able to access the referenced_by values from a given metaobject would be huge.
My gut instinct is that it is not currently possible. But hopefully it can be added to the liquid API at some point!
It’s been a wile since this was posted, however this is exactly what im searching for:
When viewing a metaobject entry in the shopify admin there is a section called “Referenced by” that lists all products
Has there been any update on this? I load metaobject of selected type (Color Variations) in liquid template, however i am just not able to access it’s references.
Example, shop by “brand”. “Brand” being a metafield linked to the “Brands” metaobject. “Brand” page (metaobject template) will list all products from the linked brand.
create metaobject, example: “brands” with brand name and other fields you may want to use - enable metaobject to be accessed from storefront and to create template;
create product metafield “brand” referring to metaobject “brands”;
create a snipped to show product grid with the “brand” metafield (ex: brand-product-grid.liquid) - code below pulls all the products (collection “shop-all”) and validates if the product metafield value is the same as from metaobject, building the grid. I only created a list of the product titles but you can render the “card-product.liquid” with all the accepted parameters;