0

I have this answer in reference :

https://wordpress.stackexchange.com/a/100657/145078

It sends to all users.

I want to notify the author of the post only when author's custom post type gets published.

Please help thanks

1

This should work — make sure to change my_custom_type to the correct CPT slug:

add_action( 'transition_post_status', 'notify_author_on_publish', 10, 3 );
function notify_author_on_publish( $new_status, $old_status, $post ) {
    if ( 'publish' !== $new_status ||
        $new_status === $old_status ||
        'my_custom_type' !== get_post_type( $post ) ) {
        return;
    }

    // Get the post author data.
    if ( ! $user = get_userdata( $post->post_author ) ) {
        return;
    }

    // Compose the email message.
    $body = sprintf( 'Hey %s, your awesome post has been published!
    See <%s>',
        esc_html( $user->display_name ),
        get_permalink( $post )
    );

    // Now send to the post author.
    wp_mail( $user->user_email, 'Your post published!', $body );
}
  • You're welcome. =) – Sally CJ Nov 7 '18 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.