I have a custom post which is submitted by the visitor from front end. Visitor's submitted post status is pending.
Now when admin change the post status from pending to publish, I want to send an email to the author of this post. author email collected by custom field.
function send_mails_on_publish( $new_status, $old_status, $post ) {
if ( 'publish' !== $new_status or 'publish' === $old_status or 'trainee' !== get_post_type( $post ) )
return;
$author = get_post_meta( $post_id, $tr_user_reg_email, true );
$body = sprintf( 'Hey there is a new entry!
See <%s>',
get_permalink( $post )
);
wp_mail( $author, 'New entry!', $body );
}
add_action( 'transition_post_status', 'send_mails_on_publish', 10, 3 );
This is what I'm trying. But this does not work. Anybody can help me? Thanks in advance :)