Loop through liquid advanced custom field to return multiple metafield values

Topic summary

A developer is attempting to loop through a Shopify Advanced Custom Field (ACF) metafield to output multiple FAQ entries (heading and content pairs from a repeating field).

Current Issue:
The loop structure appears incomplete or incorrectly formatted, with garbled/reversed text in the code snippet, making it difficult to identify the exact problem with fetching heading and content data.

Proposed Solution:
Another user suggests using forloop.index0 instead of forloop.index when accessing array elements:

  • index0 starts counting from 0, matching array indexing
  • index starts from 1, which would skip the first element

Example provided:

{% for item in alt %}
  {% assign i = forloop.index0 %}
  {{ alt[i] }}
  {{ image_description[i] }}
{% endfor %}

The solution includes screenshots demonstrating the ACF metafield app setup and expected output. The key technical point is ensuring proper zero-based indexing when accessing metafield array values in Liquid.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

I’ve built the following liquid for loop to retrieve & output data from a repeating advanced custom field in Shopify. The ACF namespace is faq, and contains heading and content data. My current loop is as follows:

<div class="feed-faqs">

    {% if page.metafields.faq != blank %}

        {% assign faqs = page.metafields.faq %}

        {% for item in faqs %}

            {% assign i = forloop.index %}
            
            <div class="item item--{{ i }}">
                {{ heading[i] }}
                {{ content[i] }}
            </div>
            
        {% endfor %}

    {% endif %}

</div>

However, on the frontend, this loop returns the following:

<div class="feed-faqs">
    <div class="item item--1">            
    </div>            
    <div class="item item--2">            
    </div>
</div>

Is what I’m trying to achieve (to output multiple values from a repeating ACF field) possible with this approach, and if so, where have I gone wrong in fetching the header & content data?

Hi @graemebryson

Please try out this.

{% if product.metafields.alt.alt != blank %}

{% assign alt = product.metafields.alt.alt %} {% assign image_description = product.metafields.image_description.image_description %}

{% for item in alt %}
{% assign i = forloop.index0 %}

{{ alt[i] }}

{{ image_description[i] }}

{% endfor %}
{% endif %}

index0 is used because it will check the loop element from 0 instead of 1, otherwise the first element will not print.

ACF metafields app -

Output -