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 );
}
Related Posts:
- Sanitizing post content for use in an email
- Custom post type without editor or revisions – Notify on update?
- How to auto send email when publishing a custom post type?
- Post Via Email to a Custom Post Type
- Sending an email when a CPT is saved/updated (NOT when it’s created)
- Email friend for each Custom Post Type posts on a page
- Send email button in custom post type backend
- Notify admin on new submit
- get_post_meta returning no value in custom post type alert email
- Adding the_content() in custom template email
- How can the recipients and content for comment email notifications on a custom post type be changed?
- How to insert data into meta box from another plugin?
- Generate new post from email
- Send email messages after comment was submitted
- Send post changes to set email addresses (not users or subscribers)
- Extending post by email
- See if the email exists or not
- CPT email notification including only new value custom fields
- Send mail to author when custom post type is saved
- BCC email to subscribers
- send email to all registered users when post expires
- CPT Metabox with email notification
- Emailing Authors only when a CUSTOM POST TYPE post is published- not when edited later [duplicate]
- How to create a job post by email parsing? [closed]
- Send email on creation of custom post type and use get_post_meta()
- Custom post type yearly/ monthly archive permalinks
- Taxonomy, Terms, and Template Files
- Quick edit screen customization
- How do I filter the excerpt metabox description in admin?
- WP_Query orderby custom field then post_date in one query
- Changing the priority of a custom taxonomy’s metabox
- Adding post tags to custom post types
- How to show more posts on an archive page?
- Pagination not working with custom category template
- Multiple post types in archives (filter?)
- Remove the Publish metabox for custom post type [duplicate]
- How to query custom post type by term?
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- How to get the first term for the current taxonomy?
- Including an External File in a Post (and Using Processed Paths)
- Notice: Undefined property: stdClass::$delete_posts with custom post type
- count_many_users_posts except current logged in user?
- How to search map address in custom post type?
- Ignore sticky posts if post is not in meta query
- Creating Accordians in WordPress Theme
- Custom Search for Drafts in Custom Post Type
- Custom Post Type with has_archive ignores my custom archive and single template
- Templates and meta
- What’s the difference between same wp functions get_posts(); functions in different form?
- Pagination on a custom post type loop
- Display all post titles of current post type
- Custom post type multiple loop by taxonomy term
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- How do I set default meta value by post type?
- How to Filter custom post type by taxonomy?
- Add custom post type settings to wordress default posts
- WP Meta query for a custom post type based on two values
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Wrap custom post type – ONLY- in a div
- Some posts from custom post type to subdomains
- WordPress subpages to custom post types
- How can I display custom post types on a page?
- calling categories in a custom post type
- How can i automatically add CPT single pages as sub menu items
- Set thumbnail and title for a post type archive (not post itself!)
- sortable columns for multiple custom post types not working
- I need to add a filter to prepend the term ‘National – ‘ to the post title if the post is tagged to multiple states
- Custom ordering of CPT items not matching with the ordering of its pagination
- Metabox multiple custom post select -> display selected items?
- Custom post type categories gives 404 error
- Query Posts that have Custom Taxonomy
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Require custom post type if is_admin() – template doesn’t show up?
- Rewrite rules for custom post type
- How can I loop at a Specific Taxonomy from a custom post type?
- Can I use the ‘category’ taxonomy for both posts and a custom post type?
- Change user role when user’s first post gets published
- Create post meta box that links another post
- In the php, how can I have a category of a custom post type display?
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- Why do my custom post type show up in all pages?
- Ajax load more inside custom post type taxonomy
- Confused about where to store my data
- Pagination for custom query returns 404
- How can I get the last 5 element of this tax query?
- Insert a hash into the url of custom posts to make them function as anchors
- Create a custom wp_query from a specific custom post type with specific taxonomy
- Custom Post Type duplicating slug for new posts
- Show posts for current taxonomy
- Cannot retrieve Custom Taxonomies (Disappeared)
- Custom Post type and Taxonomy in post URL error
- Stop Custom post type from being searched via URL
- Multiple Custom Post Type permalink issue
- How to avoid hardcoded text in a custom page template?
- How to use get_sidebar in plugin folder?
- How to Create Custom Post Type with Multiple Color Options?
- Filter CPT based on meta box value using Flexible Posts widget?
- Display Custom Post Type on Toolset Types Plugin
- Retrieve a post with its ACF repeater fields in wordpress
- Delete old thumbnail when updating new