Home › Forums › Backend Issues (wp-admin) › update_value hook not working when saving post › Reply To: update_value hook not working when saving post
More than likely you are updating the field and then ACF is overwriting it with the submitted value. acf/update_field is called when the field is being updated. So the other field has probably not been updated yet when you update it.
You need to use an acf/save_post filter and do all the work after ACF has finished saving the post https://www.advancedcustomfields.com/resources/acf-save_post/
or you need to update the $_POST[‘acf’][$field_key] value of the field you want to change.
function save_post_functions( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
if ( get_post_type( ) == 'artists') {
$artist_name = get_field('artist_name');
$artist_sort = get_field('artist_sort');
$name_sort = name_sort($artist_name);
if (substr_count($name_sort,'%')>0) { $name_sort = $artist_name; }
if (isset($_POST['acf']['field_XYZ123'])) { // replace with your field key
$_POST['acf']['field_XYZ123'] = $name_sort;
} else {
update_field('artist_sort',$name_sort,$post_id);
}
}
}
add_action('acf/save_post', 'save_post_functions', 20);
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.