Try this way:
function send_emails_on_new_event( $post ) {
$emails="[email protected]";
$headers="From: Name <[email protected]>";
$title = wp_strip_all_tags( get_the_title( $post->ID ) );
$message="New post created";
if ( get_post_type( $post->ID ) === 'documents' ) {
wp_mail( $emails, 'New Post', $message, $headers );
}
}
add_action( 'pre_post_update', 'send_emails_on_new_event' );
From the Code Reference:
pre_post_update: Fires immediately before an existing post is updated in the database.
Related Posts:
- Send post changes to set email addresses (not users or subscribers)
- send email to all registered users when post expires
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- Displaying Custom Post Types In “At A Glance” Meta Box
- Sort search results by post type
- Custom post type without editor or revisions – Notify on update?
- How to auto send email when publishing a custom post type?
- Posts to expire (deleted) after a date
- White screen error for a custom theme
- How do I add a custom post type to the Featured Content in twenty fourteen theme?
- Saving multiple Metabox contents
- Is it possible to insert text into an html tag using functions.php?
- Custom post type loops with different page templates
- Limit Authors to their Own Posts on front-end excluding admins
- Multiple Content Block
- Unable to save or update postmeta for custom post type via action using save_post hook
- How to: add option to add more checkboxes on custom post type
- Allow Users Access to Custom Post Type Only
- How do you output custom code between posts in the loop?
- How to get Custom Post ID by adding filter to child theme’s function
- Output custom post shortcode. Help spot the error.
- When ‘is_post_type_archive()’ return true?
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- How To Enable Block Editor (Gutenberg) for Existing Post Type via functions.php
- Modifying Custom Post Type after registration (will it affect content?)
- Create a post in custom post type using field in registration form after users submit form
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- right_now_content_table_end function not working?
- wp_insert_post generates endless posts
- How to target a specific custom post type post and its all children and grandchildren?
- get_post_meta not working on publishing
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- get_post_meta returning no value in custom post type alert email
- How to make custom posts types display when published for the future
- CPT archive admin menu label
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- How can the recipients and content for comment email notifications on a custom post type be changed?
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Add term to custom post type on draft
- How to assign classes to all elements?
- Different Category system needed for the Custom Post Type
- Template not working for the custom Post type
- Featured Image field not appearing in Custom post type
- Loop increase number
- ACF in wordpress
- Change Slug of a Custom Post Type
- Assign category a default post type
- List of all entries of custom-post-type: Add year-parameter?
- How to inherit field value from parent post into in child / sub post
- Custom post type’s posts are not showing anywere but in xml sitemap
- Removing full title and breadcrumb header container for a specific post type
- Show current user posts in custom post type query
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Custom post type in Custom widget – $listItem
- Meta box not appearing in my custom post type
- Redirect to URL if x number of days passed
- Display author box on just certain category posts?
- Conflict in function to allow single post template based on category
- redirect after submiting post for review
- How to divide Subcategories into pages of parent category wordpress
- how to achieve this permalink abc.com/CPTName/CustomPostTypeCategorySlug/categoryname
- set object terms after some some time of published post – functions.php
- Create WordPress User in backend, and automatically create a new post in Custom Post Type with user uame as the Title in the post
- update custom taxonomy custom fields
- Is there a way to use ‘publicly_queryable’ => false only on specific taxonomy term?
- Pagination not working in custom post type. Help
- how to display author name in custom post type
- Urgent – WordPress keeps creating posts
- ACF field check value of field on all other articles
- How to get current post type?
- How to convert Post Object Custom Field into Tags
- Problem with multi checkboxes value in metabox?
- Why is wp_list_authors not picking up Authors from CPT’s?
- Change Search display for Custom Post Type
- Create dynamic logo carousel without using any plugin
- subtracting the current post form then whole loop, which is generating all CPT titles
- fusion builder missing from custom post editor
- Stored meta from attachment, video length?
- Duplicate posts in my custom loop
- Featured image in custom post is being disabled
- custom post type does not working when adding in child theme function
- call_user_func_array() error after moving to another server
- Function not pulling image or text from custom post type
- Rich Custom Field for Custom Post type not saving
- Updating User Meta from Custom Post Field Upon Publish Not Working
- I want to split this into two functions
- Generate daily archive whenever any post type is added
- Invalid Taxonomy in template
- CPT Metabox with email notification
- Custom post type functions.php if statement on action
- Add HTML before a specific div?
- 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]
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- Send email on creation of custom post type and use get_post_meta()
- I want to show a list of posts under specified categories
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs
- Is it possible to use a post name in a custom post slug?