Repeater inside Group ACF Wordpress

Repeater inside Group ACF Wordpress

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Repeater Inside Group ACF: Fixing Array to String Conversion

When nesting Advanced Custom Fields (ACF) repeaters, specifically placing a repeater inside a group field that is itself nested within another repeater, developers often encounter the "Notice: Array to string conversion" error. This issue usually stems from a misunderstanding of how ACF structures its data and how WordPress functions handle that structure during iteration.

The root cause in your specific scenario lies in this line:
have_rows( $horlur['arsmodeller_lankar'] )

You are passing the value retrieved from get_sub_field('horlur') directly into have_rows(). However, if the field type of horlur is a Repeater or a Group containing a Repeater, get_sub_field() returns an array representing that entire field group. You cannot pass an array to have_rows(), which expects a single string representing the field name (e.g., 'start_horlurar').

To resolve this, you must iterate through the repeater fields first before attempting to access their internal values. ACF stores repeater data as an indexed array where each item contains the sub-fields defined within that repeater row. You need to loop over has_rows('horlur') or check if the $horlur variable is populated and iterate through its keys.

Here is the corrected logic flow. First, ensure you are iterating through the outer repeater correctly using have_rows(). Then, retrieve the sub-field value. If that sub-field is a nested repeater or group, you must treat it as an array of items.

if ( have_rows('start_horlurar') ) {
    while ( have_rows('start_horlurar') ) : 
        the_row(); 

        // Retrieve the 'horlur' sub-field. This is likely an array if it's a repeater/group.
        $horlur = get_sub_field('horlur');

        // Only proceed if we actually have data for this item
        if ( !empty($horlur) ) {
            
            // Check if the nested field 'arsmodeller_lankar' exists within this row's data
            // We need to check if the key exists in the $horlur array
            if ( isset($horlur['arsmodeller_lankar']) ) {
                
                // If 'arsmodeller_lankar' is a Repeater, it will be an array of rows.
                // We must loop through these rows to call have_rows().
                $nestedRows = $horlur['arsmodeller_lankar'];

                if ( is_array($nestedRows) && !empty($nestedRows) ) {
                    foreach ($nestedRows as $row) {
                        // Now we can safely access the 'lank' field within each nested row
                        echo get_sub_field('lank', $row); 
                        
                        // Alternatively, if you are strictly using have_rows() for the inner loop:
                        // Note: You generally shouldn't nest have_rows() loops like this unless
                        // the data structure is a repeater inside a repeater in a specific way.
                        // The foreach approach above is usually cleaner for Repeater-to-Repeater.
                    }
                }
            }
        }

    endwhile;
}
endif;

Understanding the Data Structure

The critical distinction here is between the Field Name and the Field Value. When you use have_rows('field_name'), WordPress looks up a specific field name in the database. However, when you retrieve data with get_sub_field(), you are pulling the value stored in that field.

If your ACF setup defines horlur as a Repeater, and inside that repeater there is a Group containing a Repeater called arsmodeller_lankar, the data looks like this:

$start_horlurar [Repeater]
  [0] -> horlur [Group/Repeater]
         -> arsmodeller_lankar [Repeater]
             [0] -> lank [Text]
             [1] -> lank [Text]

Your original code attempted to treat the value of horlur (which is an array of rows) as if it were a field name (a string). That mismatch triggers the PHP notice because PHP tries to cast the array to a string implicitly when passing it to the function expecting a string argument.

Best Practices for Nested ACF

When designing nested repeater structures in ACF, consider these trade-offs:

  1. Performance: Deep nesting increases database query complexity. Ensure you are not looping unnecessarily. If arsmodeller_lankar is optional, always check isset() before accessing it to prevent undefined index notices.
  2. Output Control: Using get_sub_field('lank', $row) inside a foreach loop is generally more efficient than trying to nest while(have_rows()) calls if the inner structure is a standard repeater array. It avoids redundant SQL queries for the outer loop's context.
  3. Field Types: If the inner field arsmodeller_lankar is a Group rather than a Repeater, you do not need to loop over it; you can access its sub-fields directly as long as they are defined in the group schema.

By correctly identifying whether a retrieved value is an array of rows or a single string field name, you eliminate the type conversion errors and ensure your template renders the nested content as intended.

Our network