Sending 2 duplicate emails when custom post published
-
Hi there,
Trying to figure out a mystery and just can’t – maybe someone can help:
I would like an email to be sent to the author of a custom post after I, as the admin, publish the post (change status from pending to published). I used the code on this blog post, adding it to my functions.php file in my theme:
Notify AuthorsThe code is as followed:
//Notify Authors when Article Published function wpr_authorNotification($post_id) { $post = get_post($post_id); $author = get_userdata($post->post_author); $message = " Hi ".$author->display_name.", Your post, ".$post->post_title." has just been published. Well done! "; wp_mail($author->user_email, "Your article has been published. Please check the article and let us know if anything needs to be changed. Please do not forget to Tweet, Like, and Google +1 the article. ", $message); } add_action('publish_listing', 'wpr_authorNotification');
The code does work, HOWEVER, when it sends two emails instead of 1 to the user – no matter what. Interestingly, if the add_action line is:
add_action(‘publish_post . . . instead of publish_listing (listing is the name of my custom post type), then it sends only 1 email.Why would a custom post type cause the system to generate 2 emails instead of 1?
So confused -thanks in advanced!
kevin
- The topic ‘Sending 2 duplicate emails when custom post published’ is closed to new replies.