I have some code that uses the WordPress save_post Action to manipulate data in a post type.
I am copying the text from a post meta field into the post title and then calling wp_update_post().
The title is never updated. If I disable ACF, the code works. It appears that my code is calling wp_update_post() and then ACF is calling wp_update_post() afterward and overwriting my update.
I tried changing the priority to 99 and 999, but ACF is still overwriting any updates I do.
This code fails every single time:
add_action( 'save_post', 'am_save_post_handler', 999, 2 );
function am_save_post_handler( $post_id, $post ) {
update_field( 'client_contact_phone', '99 Boogie', $post_id );
}
client_contact_phone is a field managed by ACF and it never gets updated.
This code works every single time:
add_action( 'save_post', 'am_save_post_handler', 999, 2 );
function am_save_post_handler( $post_id, $post ) {
update_field( 'client_contact_phoneXX', '99 Boogie', $post_id );
}
client_contact_phoneXX is not managed by ACF, so it gets updated.