i have a meta box for some email address and i save value in save_post hook
add_action( 'save_post', 'sm12_save_post' );
function sm12_save_post( $postid ){
update_post_meta( $postid, '_some_email_address', $_POST['some_email_address'] );
}
Now i want to send email to this email address only when this post is published. So i use
add_action( 'publish_post', 'sm12_publish_post' );
function sm12_publish_post( $postid ){
$email = get_post_meta( $postid, '_some_email_address', true );
if( ! $email )
return;
$sub = 'test subject';
$mgs = 'test message';
wp_mail( $email, $sub, $mgs );
}
if post is saved in any other status other than 'publish' then it sends email when publish, but if post is directly publish it can not send email, because 'publish_post' is called before 'save_post' and meta is not yet available there. how to send email only when published in my case? should not call wp_transition_post_status() last of everything during save?