Good afternoon community,
I am trying to access the data of a product that is connected to another, via a metafield.
I have added the metafield to the product, as below:
I want to access the title of the ‘sample’ on the product page, to do this I have added:
{% assign sample = product.metafields.custom.sample2 %}
{{ sample.title }}
However, nothing appears. I know the reference I am using is correct as when I add ‘{{ sample }}’ to the code, I get “gid://shopify/Product/<product_id>” rendered on the page. Usually adding ‘.value’ works for metafields, variants or media, but nothing renders.
Let me know if you need anything further information from me.
Many thanks,
Alysha
Hi @AlyshaJohnson
It seems the issue is related to accessing the title of the linked product through the metafield. The value gid://shopify/Product/<product_id> confirms the reference is being fetched, but Shopify Liquid doesn’t natively allow fetching data from another product dynamically.
Here’s how you can resolve it:
- Use Shopify’s Storefront API or GraphQL to query the product details, including its title.
- Alternatively, pre-store the title directly in another metafield.
If you’re aiming to optimize your product pages for SEO, tools like SEOPro can help identify and resolve SEO issues effectively. It audits products, suggests improvements, and offers bulk optimization features, making it easier to enhance your SEO strategy.
Full disclosure: We are the developer of this app. Feel free to reach out to us: [email removed]
Phil
Seopro Developer
1 Like
Hi Phil,
Thank you for your suggestion of using Shopify’s Storefront API - I could query all product details!
Kind Regards,
Alysha