I want to generate post title from first name and last name which are two fields. The posts are generated in WS Form and saved with no title.
I tried this code however it does not seem to work. Any thoughts?!
function set_post_title_from_acf($post_id){
$my_post = array();
$my_post['ID'] = $post_id
if (get_post_type($post_id) == 'staff'){
$first_name = get_field('first_name',$post_id);
$last_name = get_field('last_name',$post_id);
$my_title = $first_name . ' ' . $last_name;
$my_post['post_title'] = $my_title;
$my_slug = sanitize_title($my_title);
$my_post['post_name'] = $my_slug;
wp_update_post($my_post);
}
}
add_action('save_post','set_post_title_from_acf',20);