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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.