So you first tried hooking on to wp_insert_post_data
and could save the meta data when saving Drafts but not when publishing. Then you tried hooking on to save_post
and could save meta data when publishing but not when saving Drafts.
The easiest solution would be to hook on to both.
add_action('save_post', 'save_details');
add_action('wp_insert_post_data', 'save_details');
Edit
Both save_post
and wp_insert_post_data
are called at the same time and pass two parameters to callback functions. In the source, it looks like this:
do_action('save_post', $post_ID, $post);
do_action('wp_insert_post', $post_ID, $post);
Bbut your function isn’t accepting any parameters. This will make return $post_ID
fail and will likely cause other issues as well.
You should have:
function save_details( $post_ID, $post ) {
...
}
And your hook should be:
add_action( 'save_post', 'save_details', 10, 2 );
This will pass both $post_ID
and $post
into your function and should make things run a bit more smoothly.