First, you can use this hook to target only one custom type:
https://developer.wordpress.org/reference/hooks/save_post_post-post_type/
This hook (and save_post
) is called the first time when you click on “new …” and then the hook is called with $update = FALSE
.
Then to send e-mail only when the object is updated, you can test $update
like this:
const UTILITY_SEARCH_POST_TYPE = "utility-search";
add_action("save_post_" . UTILITY_SEARCH_POST_TYPE, function ($post_ID, $post, $update) {
if (wp_is_post_autosave($post_ID)) {
return;
}
if (!$update) { // if new object
return;
}
// preparing e-mail
...
// sending e-mail
wp_mail(...);
}, 10, 3);
Related Posts:
- Why does save_post action fire when creating a new post?
- Exclude trash from save_post
- Call add_action() in function wordpress
- Write automatic title at save_post (infinite loop)
- Add meta field after post has been published
- Create post revision on slug change
- Can’t Get Metabox Data Saved Assistance Needed
- Run a function on all posts
- add_action( ‘publish_pelicula’, ‘post_published_notification’, 10, 2 ); does not trigger propperly
- save_post not triggered when a post is updated
- WordPress sent multiple requests on update
- Add Tag to post after publishing
- Hook into admin_notices after sending mail
- save_post action not firing when save
- save post running twice and creating two database entries – how do I disable this?
- A way to see real changes of posts inside an action?
- add_action reference a class
- Remove parent theme action in child
- How to do_action and get a return value?
- Remove an action from an external Class
- Does the event ‘wp_version_check’ even exist? What is it doing?
- Difference between do_action(‘admin_enqueue_scripts’, $hook_suffix) and do_action(“admin_print_styles-$hook_suffix”) syntax
- Cron jobs in a class
- Custom post type save_post action not firing
- When and Where to use wp_insert_post()
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Why can’t I hook into save_posts after admin_init?
- enqueuing React script and hooking its target div fails to load script
- wp_logout action not working
- Using auth_redirect returns cannot modify header information
- What would cause the ‘wp’ action to fire twice per page (but only once per post) in Firefox only?
- I don’t understand why I need a lower priority to remove an action with a higher priority to make it work
- wp_get_attachment_metadata returns false with add_action() ‘add_attachment’ hook
- Manually add admin bar
- Is there a way to expose additional fields to the Bulk Action > Edit functionality?
- do_action pass array argument as reference not copy [duplicate]
- Why Should We Use wp_clear_scheduled_hook and What it Does?
- Scheduled event won’t fire
- When should I call add_settings_section and add_settings_field?
- update_post_meta() whenever custom post type is updated
- Unable to show error message using wp_login action
- Usage of do_action and add_adction
- WP action is not triggering a do_action() call within?
- where is the documentation for add_action() parameters?
- How to set a different value in the generator meta tag?
- Validate form in functions.php, send errors back to template
- Set default Custom Post Meta Value
- What is the callback sent to add_submenu_page() invoked by WordPress?
- remove_action returns FALSE
- Remove action from shortcode
- How to get $tag to fill into add_action() or add_filter()?
- Is there way to run a code every time when any cron is run?
- Remove Action from Plugin within extended class and no assigned variable
- Action when sidebars updated
- Payment before publishing post
- How to access author data from header action
- Content won’t load when using action the_content
- How can I unhook this action that was added via $this?
- add_action on a specific page
- save_post action doesn’t passing post id to my function as argument
- Update media library image shown in “attachment details” when using wp_insert_attachment to add item to the media library
- How to find where an action is triggered? [closed]
- Form action unfamiliar
- Why is my css and js not enqueued until footer?
- Why does my delete_post hook get called twice
- Which hook to add action on specific page?
- Action Scheduler not running
- W3TC manual cache flush does not work
- Adding php to form action breaks code [closed]
- add_action.. will work if function is empty?
- call custom action after delete account
- Dynamic name of cron event
- Trying to write a function in an external php file to manage admin menu visibility
- remove_action: Initial attempt failed while a later attempt worked
- Action inside another action not working
- register_post_type not working in wordpress 3.6
- action wp_set_comment_status never gets fired when i change the comment status [closed]
- How to use add_action inside files included by theme’s functions.php
- What do I put in the form action attr on top of form wordpress
- do_action in API call
- Custom query_var to get URL paramater not working
- do_action doesn’t trigger if it’s in a template that gets loaded via REST endpoint
- add_action where function has arguments
- Add Action wp_update_post not Updating WYSWIAG editor
- Remove action from plugin
- remove action from woocommerce file
- WP_LIST_TABLE bulk action
- Understanding and using did_action() in a conditional statement
- Adding a conditional to work on certain pages/page templates to an add_action()
- Adapting functions from Genesis theme
- Dealing with html forms [closed]
- Cannot Schedule Sending An Email
- Invoke a function before the action hook
- using media_handle_sideload() to add mp4 files to Media Library
- OOP – add_action
- do_action in header, add action later?
- Passing arguments in add_action inside search template
- Problem with executing a function on saving a post
- Return $post_id when DOING_AUTOSAVE?
- remove an action hook function on a plugin from a theme