edit_post_(post_type) │ action-hook │ WP 5.1.0

Fires after an existing post of the specified type is updated in the database.

Replace the dynamic (post_type) part with the post type name:

In wp_insert_post(), the action fires when updating a post (when an ID is specified) or through wp_update_post(). The call is skipped when inserting a new post.

Saving from the editor may update an already created auto-draft.

The hook is not limited to the admin area. In core, it is also called:

When updating through wp_insert_post(), the actions run in this order:

Infinite recursion

Calling wp_update_post() for the same post inside the callback triggers this hook again and can lead to infinite recursion. Therefore, temporarily disable your callback with remove_action() before the nested update, then add it again.

The $fire_after_hooks = false parameter of wp_insert_post() does not disable this action.

Use save_post_(post_type) to handle both post creation and updates.

Use post_updated to compare post fields before and after an update.

Use wp_after_insert_post to run after the post, its terms, and its meta-fields have been saved.

This hook is skipped when an attachment is updated through wp_insert_post(): use edit_attachment or attachment_updated.

Usage

add_action( 'edit_post_(post_type)', 'wp_kama_edit_post_type_action', 10, 2 );

/**
 * Function for `edit_post_(post_type)` action-hook.
 * 
 * @param int     $post_id Post ID.
 * @param WP_Post $post    Post object.
 *
 * @return void
 */
function wp_kama_edit_post_type_action( $post_id, $post ){
	// action...
}
$post_id(integer)
ID of the updated post.
$post(WP_Post)

Post object. To receive it in the callback, pass 2 as the fourth argument to add_action().

When called from wp_update_comment_count_now(), the object was loaded before the count was updated, so $post->comment_count contains the previous value.

To get the current data, retrieve the post again with get_post( $post_id ). If you need the old and new comment counts, use wp_update_comment_count.

Examples

#1 Clear the book card cache after an update

Suppose book card data is stored in the myplugin_book_{ID} transient. Delete it after a book post is updated so the application regenerates the card on the next request.

add_action( 'edit_post_book', 'myplugin_clear_book_cache' );

function myplugin_clear_book_cache( $post_id ) {
	delete_transient( 'myplugin_book_' . $post_id );
}

Changelog

Since 5.1.0 Introduced.

Where the hook is called

wp_insert_post()
edit_post_(post_type)
WP_Customize_Manager::trash_changeset_post()
edit_post_(post_type)
wp_publish_post()
edit_post_(post_type)
wp_update_comment_count_now()
edit_post_(post_type)
wp-includes/post.php 5232
do_action( "edit_post_{$post->post_type}", $post_id, $post );
wp-includes/class-wp-customize-manager.php 3112
do_action( "edit_post_{$post->post_type}", $post->ID, $post );
wp-includes/post.php 5455
do_action( "edit_post_{$post->post_type}", $post->ID, $post );
wp-includes/comment.php 3159
do_action( "edit_post_{$post->post_type}", $post_id, $post );

Where the hook is used in WordPress

Usage not found.