Home › Forums › Add-ons › Repeater Field › update a acf sub_field with the value from a different sub_field › Reply To: update a acf sub_field with the value from a different sub_field
Your code works, but only for a text field, not for a repeater field.
I got it working for a repeater field using the code below:
`function my_acf_post_fields($post_id){
$post_id = get_the_id();
$post_author_id = get_post_field( ‘post_author’, $post_id );
if( have_rows(‘add_full_address’, ‘user_’ . get_post_field( ‘post_author’, $post_id )) ):
$i = 0;
while( have_rows(‘add_full_address’, ‘user_’ . get_post_field( ‘post_author’, $post_id )) ) : the_row();
$i++;
$value{$i} = get_sub_field(‘add_address_1’);
$value2{$i} = get_sub_field(‘add_address_2’);
$value3{$i} = get_sub_field(‘add_city’);
$value4{$i} = get_sub_field(‘add_zip_code’);
if( have_rows(‘c_address_of_your_clinics’) ) {
$i = 0;
while( have_rows(‘c_address_of_your_clinics’) ) {
the_row();
$i++; update_sub_field(‘c_address1’, $value{$i});
update_sub_field(‘c_address2’, $value2{$i});
update_sub_field(‘c_city’, $value3{$i});
update_sub_field(‘c_zipcode’, $value4{$i});
}
}
endwhile;
endif;
}
add_filter(‘acf/save_post’, ‘my_acf_post_fields’, 20);
However, it is not lopping through all the rows, it stops at the first row.
How do I make it look through and display all the row values.
Do I need to change the order of the if() and while() loops?
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.