do_action( "save_post_{$post->post_type}", int $post_id , WP_Post $post , bool $update )
Fires once a post has been saved.
Description
The dynamic portion of the hook name, $post->post_type
, refers to the post type slug.
Possible hook names include:
save_post_post
save_post_page
Parameters
-
$post_id
int -
Post ID.
-
$post
WP_Post -
Post object.
-
$update
bool -
Whether this is an existing post being updated.
Source
File: wp-includes/post.php
.
View all references
do_action( "save_post_{$post->post_type}", $post_id, $post, $update );
Changelog
Version | Description |
---|---|
3.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
The hook also fires when clicking on the “Add New” option for the custom post type, as it creates the draft in the DB, and when calling the
wp_update_post
function as well.Top ↑
Feedback
You can know whether the hook fired from the “Add New” option by checking the post status:
It’s also good to note that this hook is also called when trashing a post or restoring it from trash. — By Benjamin Intal —
It’s kind of sad that this more explicit action fires before the less explicit ‘save_post’ action.
This means if a 3rd party plugin does something using ‘save_post’ you need to use ‘save_post’ to override it too.
Notify your newsletter subscribers when a new book (custom post) is added-