Home › Forums › Add-ons › Repeater Field › Automatically generate repeater fields › Reply To: Automatically generate repeater fields
Hi @jetro157,
I think the second one would be easier to achieve. If you only need to show the duration on the front-end, you can use the count() function on the repeater field. It should be something like this: count(get_field('repeater_field_name'))
.
If you need to show it on the backend, you can use acf/save_post to update the duration field using update_field(). Maybe something like this:
<?php
function my_acf_save_post( $post_id ) {
$itinerary = get_field('itinerary_field_name');
if ($itinerary){
$duration = count($itinerary);
update_field('duration_field_name', $duration, $post_id);
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
?>
I 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.