Support

Account

Home Forums Add-ons Repeater Field Automatically generate repeater fields Reply To: Automatically generate repeater fields

  • Hi @jetro157,

    I think you need to get the repeater fields first from the flexible field. Maybe something like this:

    <?php
    
    function my_acf_save_post( $post_id ) {
        
        if( have_rows('flexible_content_field_name', $post_id) ):
    
            $current_duration = intval(get_field('duration_field_name'));
            
            while ( have_rows('flexible_content_field_name', $post_id) ) : the_row();
                if( get_row_layout() == 'itinerary_layout' ):
    
                    $itinerary = get_sub_field('itinerary_field_name');
                    if ($itinerary){
                        $duration = count($itinerary);
                        $current_duration = $current_duration + $duration;
                    }
    
                endif;
            endwhile;
            
            update_field('duration_field_name', $current_duration, $post_id);
            
        endif;
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
    ?>

    Keep in mind that I haven’t tested it yet. Please fix the error message as needed.

    Hope this helps.