Email to subscribers custom post type content
-
Hi all,
I’m trying to find a way to email custom post type contents to all subscribers upon publishing that custom post type. I found similar solution on stackoverflow: https://wordpress.stackexchange.com/questions/100644/how-to-auto-send-email-when-publishing-a-custom-post-type
add_action( 'transition_post_status', 'send_mails_on_publish', 10, 3 ); function send_mails_on_publish( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status or 'publish' === $old_status or 'my_custom_type' !== get_post_type( $post ) ) return; $subscribers = get_users( array ( 'role' => 'subscriber' ) ); $emails = array (); foreach ( $subscribers as $subscriber ) $emails[] = $subscriber->user_email; $body = sprintf( 'Hey there is a new entry! See <%s>', get_permalink( $post ) ); wp_mail( $emails, 'New entry!', $body ); }
That particular solution sends a generic email to subscribers. What I want is to include the contents of the custom post type in the email. Kind of like a newsletter, but using custom post type.
- The topic ‘Email to subscribers custom post type content’ is closed to new replies.