How to find the Product by Id in theme

Topic summary

A developer is working on a Shopify theme extension and needs to find a product using its global ID (GID) format: gid://shopify/Product/8789. They want to know how to locate this product in Liquid and convert it properly.

Response provided:

  • The solution depends on which page the product ID is needed
  • On Product Pages: Access directly using {{ product.id }}
  • On Collection Pages: Loop through products:
    {% for c in collection.products %}
      {% assign pId = c.id %}
      {{ pId }}
    {% endfor %}
    

Status: The question remains partially answered, as the responder asked for clarification about the specific page context, but the original poster hasn’t confirmed whether these standard methods address their GID conversion need.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hi All,

I am currently working on a theme extension. I have a product ID in the following format: gid://shopify/Product/8789. How can I find this product in Liquid and convert it properly?

Any help would be appreciated!

On which page you need to find the product ID?

Example:-

  1. On Product Page
    You get directly by using {{ product.id }}

  2. On Collection Page
    Here you will get by looping through
    f{% for c in collection.products %}
    {% assign pId = c.id %}
    {{ pId }}
    {% endfor %}