0

I would like to display the title of blog posts but the only thing that renders me is ulr addresses. This is how I display links from metafields:

{% for field in product.metafields.custom.related_product_with_blog_post.value %}
  <div><a href="{{ field.url }}">{{ field.url }}</a></div>
{% endfor %}

How to get to article object and display all article titles from metafields?

1 Answer 1

0

You already have your article object inside of the field variable. To fetch the blog post/ article's handle, just use field.handle.

See all available properties for the article object in the Shopify API docs.

4
  • {% for field in product.metafields.custom.related_product_with_blog_post.value %} <div><a href="{{ field.url }}">{{ field.title}}</a></div> {% endfor %} return nothing :/
    – User1987
    Jan 17 at 8:39
  • Are you sure the related_product_with_blog_post metafield allows multiple values (a list) ? You can check the metafield definition to confirm that. If it only accepts a single value then you don't need to access the value property. Just use product.metafields.custom.related_product_with_blog_post without a for loop. Jan 17 at 13:43
  • My code returns me 2 url blog posts because that's how many metafields I have completed so far and now I have to take blog-handle and article-handle from it.
    – User1987
    Jan 18 at 7:29
  • As stated in my answer, you can access any information about the article in the article object's properties. The object has a handle property. That might be what you're looking for. Jan 18 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.