Home › Forums › ACF PRO › update repeater field on acf/save_post › Reply To: update repeater field on acf/save_post
@John Huebner:
Thanks for your code! This works great, however there were 2 minor syntax errors in your code. Updated code:
function post_updating_callback( $post_id ) {
$repeater = 'page_sections'; // the field name of the repeater field
$subfield1 = 'page_section_title'; // the field I want to get
$subfield2 = 'page_section_slug'; // the field I want to set
// get the number of rows in the repeater
$count = intval(get_post_meta($post_id, $repeater, true));
// loop through the rows
for ($i=0; $i<$count; $i++) {
$get_field = $repeater.'_'.$i.'_'.$subfield1;
$set_field = $repeater.'_'.$i.'_'.$subfield2;
$value = get_post_meta($post_id, $get_field, true);
$new_value = sanitize_title($value);
update_post_meta($post_id, $set_field, $new_value);
}
}
add_action('acf/save_post', 'post_updating_callback', 20);
Thanks a lot!
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.