Hook into transition_post_status
, fetch the users and send an email to all users.
Sample code, not tested:
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 );
}
You should probably use the Bcc
field.
Related Posts:
- Attach a Custom Post Type to a Woocommerc product as a variation or add-on [closed]
- Sanitizing post content for use in an email
- Custom post type without editor or revisions – Notify on update?
- Post Via Email to a Custom Post Type
- Want to turn WordPress into a paid subscription directory
- 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
- Update Post Status On Woocommerce Payment Complete
- 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 email to author of the post when the custom post status changes to published
- 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()
- How to limit the number of terms (terms acts like categories)
- Removing custom post type from link search results
- Search multiple custom fields by using meta_query
- How can I get next/ previous post links to order by a filter (by the last word of the title)?
- Filtering Posts by Multiple Taxonomy Terms such as in an Admin Post Listing?
- Check if current user has post in post type and is author role
- Pagination on a custom page template
- Create Pages from Database
- Add multiple Visual Editors for Custom Post Type
- On clicking on the category name the page is redirecting on 404 pge
- Adding a span when custom post type is updated
- Category base to url in custom post type/taxonomy
- Pull image from ACF field in a Custom Post Type
- Limit access to page depending on user level
- Is it possible to use pages to apply static content to each taxonomy level?
- Add custom post types stats to a custom dashboard widget
- Bug when editing custom post type category?
- Retrieving list of Custom Post Types
- How to remove default tag and category options form a custom post type admin menu
- How to create shortcode to display custom field value on a custom post type
- Convert simple SQL Query to WordPress query
- How to set up multisite for multi language?
- Order query using custom meta data
- Get latest 3 posts from multiple CPT in one query
- Categories of Custom Post throws gives 404
- Ajax Custom Post Filter is not filtering
- Need Output Custom Taxonomy from Custom Post Type
- Display all taxonomy terms, add class if term applies to current post
- Woocommerce search pagination not working
- Completely remove custom post type permalinks (“One Page” website)
- WordPress custom post type split into pages
- Custom Post Types hierarchy and rewrite
- How do I know the ‘meta_key’ for ordering my custom post type
- How to get the intersection of two terms both from different custom taxonomies
- Custom post type’s permalink adds the name of the post type before the post name
- Checking if $_FILE isset for an array of file upload metaboxes
- Which custom post type does the current post belong to?
- Custom post type showing same Post on all Pages
- WordPress Custom Post Type – show only certain posts that have specific taxonomy set
- How to get specific post meta by title or id
- Why are some of my custom posts not showing up on my page?
- Populate a custom field dropdown with post titles by author
- Use core block functionality in a custom block gutenberg
- Add form after woocommerce admin order edit
- Get assigned post categories
- Is there SEO or related limitations to using Custom Post Types instead of WPMU?
- Custom Post Type and Taxonomy Loop Output Is Wrong
- Multiple custom post types showing up in edit.php
- How do I get the index for a custom post?
- Commas not displaying in implode
- “Cannot redeclare cpt_reg_tax()” because of functions.php
- custom taxonomy listing returns no posts
- Custom Post Type and Breadcrumbs Conflict
- Reveal Foundation modal displaying repeat content on all modal rather dynamic content
- Custom Post Type Category Displaying ALL Sub Categories as well
- Custom Endpoint For Specific Custom Post Type
- How to only display all posts to a custom User Role?
- Display posts of a hierarchical custom post type excluding parent posts
- Wrap an X amount of taxonomy posts in a separate Row in WordPress
- Looping through custom taxonomy in one template
- get_post_meta for Custom Post Type ( CPT )
- Site loads very slow for archive custom post type page
- How to get $post object available inside functions.php to localize script?
- How can I base a query off of the current page post type AND a meta value from another custom post type
- Redirect permalinks after creating custom post types
- Plugins for putting Custom Post Types into the Menu
- Fallback if statement based on the number filtered from it
- Cannot get query var ‘post_type’ to work
- Custom Post Types, Taxonomies and Terms… I’m getting confused now!
- Don’t display post if post has empty body
- Posts picking up old Permalinks, how to reset?
- Remove slug from Custom Category Permalink + dual-category permalinks