Support

Account

Home Forums Add-ons Repeater Field Generate XML using sub_fields recursively Reply To: Generate XML using sub_fields recursively

  • Hi @bart-gopnik

    In this case, you need to create a function to loop through the returned fields and its values. Here’s an example how to do it:

    // Create function that will loop through the array
    function print_array_value($value){
        if( is_array($value) ){
            foreach( $value as $k => $the_value ){
                echo '<' . $k . '>' . PHP_EOL;
                print_array_value($the_value);
                echo '</' . $k . '>' . PHP_EOL;
            }
        } else {
            echo $value . PHP_EOL;
        }
    }
    
    // Loop through the fields here
    foreach($fields as $field){
        
        echo '<' . $field['name'] . '>' . PHP_EOL;
        
        // Check if this is a repeater or not
        print_array_value($field['value']);
        
        echo '</' . $field['name'] . '>' . PHP_EOL;
    }

    Because this is more related to PHP than ACF, kindly get in touch with PHP community for more support.

    I hope this helps 🙂