Hello to all
I have a function that sends a notification to the author of an article once their article is published using the transition_post_status hook.
I have no problem with the notification itself using the transition_post_status hook but I can't get the value of the fields I want to display in the message sent.
Here is my function:
add_action( 'transition_post_status', 'notify_author_on_publish', 20, 3 );
function notify_author_on_publish( $new_status, $old_status, $post_id ) {
$post = get_post($post_id);
// Get the post data.
$author_email = rwmb_meta( "author_email", "", $post_id );
$firstname = rwmb_meta( "firstname", "", $post_id );
if ( 'publish' !== $new_status ||
$new_status === $old_status ||
'my-custom_post-type' !== get_post_type( $post ) ) {
return;
}
$subject = "Hi " . $firstname. ", your post has been approved: " . $post->post_title . "";
$body = "Hi " . $firstname. "and so on...";
wp_mail( '[email protected]', $subject, $body ); //Issue: cannot get $author_email value.
Thanks a lot for your help