What's your biggest current challenge? Have your say in Community Polls along the right column.

Access to product data which is connected to another product via metafield.

Solved

Access to product data which is connected to another product via metafield.

AlyshaJohnson
Shopify Partner
2 0 0

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:

metafield-setup.png

 

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

Accepted Solution (1)

philForumSEOPro
Excursionist
16 3 3

This is an accepted solution.

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:

  1. Use Shopify's Storefront API or GraphQL to query the product details, including its title.
  2. 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: support@seo-pro.app

 

Phil

Seopro Developer

Hope this can help you,

If our suggestions are useful, please let us know by giving it a like or marking it as a solution. Thank you

View solution in original post

Replies 2 (2)

philForumSEOPro
Excursionist
16 3 3

This is an accepted solution.

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:

  1. Use Shopify's Storefront API or GraphQL to query the product details, including its title.
  2. 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: support@seo-pro.app

 

Phil

Seopro Developer

Hope this can help you,

If our suggestions are useful, please let us know by giving it a like or marking it as a solution. Thank you
AlyshaJohnson
Shopify Partner
2 0 0

Hi Phil,

 

Thank you for your suggestion of using Shopify's Storefront API - I could query all product details!

 

Kind Regards,

Alysha