Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I have tried the following approach, but it doesn't work. I wonder how I can get the size of the metafields list.
{% if product.metafields.products.related.value.size > 0 %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Where {% product.metafields.products.related.type %} is list.product_reference.
Solved! Go to the solution
This is an accepted solution.
Hi @henglw0621,
Sorry for the confusion, you can use the following code:
{% if product.metafields.products.related.value != blank %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Hope it helps!
Hi @henglw0621
Can you let us know where you want to display the metafields and the theme which you are using?
Hi @Tinytasks, thank you for reply.
I am using the following theme and display the metafields on the product page.
Hi @henglw0621,
You can refer: https://shopify.dev/api/liquid/objects#paginate
Hope it helps!
Hi @LitExtension, thank you for reply.
I have checked the pagination reference you provided, but I don't know how I can apply it to my code. I would appreciate if you could give me some example code on how to apply pagination with the metafield list.
This is an accepted solution.
Hi @henglw0621,
Sorry for the confusion, you can use the following code:
{% if product.metafields.products.related.value != blank %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Hope it helps!
Although this has been solved, here is a simpler solution:
Size of Metafield list = {{ product.metafields.products.related.value | size }}
{% liquid
assign related_products = product.metafields.products.related | split: ','
echo related_products | size
%}
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025