I have a function that will update the title of the post based on an ‘advanced custom field’.
It works on existing posts, but not when I create a new post. When I try and save the post and check the post listings, it isn’t there.
Any help would be greatly appreciated.
function my_post_title_updater( $post_id ) {
if ( get_post_type() == 'equipment' ) {
$my_post = array();
$my_post['post_title'] = get_field( 'item_name', $post_id );
wp_update_post( $my_post );
}
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 20);
I wasn’t adding the ID into the new array.