Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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:
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.
Cheers,
Cam
Hi @CamDWH
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!
This can be achieved by using storefront filtering.
filter.p.m.YOUR_METAFIELD_NAMESPACE.YOUR_METAFIELD_KEY=METAOBJECT_GLOBAL_ID_URL_ENCODED
for example, my namespace is farmlink, metafield is producer, and gid://shopify/Metaobject/52723384482 is the ID of the metaobject:
/collections/all?filter.p.m.farmlink.producer=gid%3A%2F%2Fshopify%2FMetaobject%2F52723384482
That sounds like it would work, thank you for sharing that! I will definitely try that out next time I run into this.
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.
Any solutions aroud?
Thanks in advance!
I'd also love to see this supported in the liquid. I've been digging around and can't find a solution even by looping over `shop.metaobjects.` etc
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024