Well because your code seems like to be bugy/not full – i wrote my code. This will add one meta box with one text field in post (you can change it to be added in your custom post_type)- Post title. Also i had to use QUERY to update/add title, because i can not find any other way, $post->post_title="some title"
do not work.
If you happy with this code – please mark as good answer, good luck 🙂
EDIT:
// Save post with your title
function save_the_title($post_id) {
global $wpdb;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
$newtitle=""; // SET YOUR TITLE HERE
$old_title = get_post_meta($post_id, '_title', true);
if($newtitle != '' && $newtitle != $old_title) {
update_post_meta($post_id, '_title', $newtitle);
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_title = %s WHERE ID = %d ",$title1,$post_id) );
}
}
add_action('save_post', 'save_the_title'); // save the custom fields