post_updatedaction-hookWP 3.0.0

Fires after an existing post is updated.

Usage

add_action( 'post_updated', 'wp_kama_post_updated_action', 10, 3 );

/**
 * Function for `post_updated` action-hook.
 * 
 * @param int     $post_id     Post ID.
 * @param WP_Post $post_after  Post object following the update.
 * @param WP_Post $post_before Post object before the update.
 *
 * @return void
 */
function wp_kama_post_updated_action( $post_id, $post_after, $post_before ){

	// action...
}
$post_ID(integer)
The post ID.
$post_after(WP_Post)
The post object after it was updated.
$post_before(WP_Post)
The post object before it was updated.

Examples

#1 Purge the cache when a post is updated on siteground.com hosting

siteground.com hosting uses Dynamic Caching, which may cache custom requests and not purge them when posts are updated, even when the hosting provider's SG Optimizer plugin is installed. This can be done manually in the plugin, but it can also be automated using the plugin's sg_cachepress_purge_cache() function.

add_action( 'post_updated', 'purge_cache_after_post_updated' );

public function purge_cache_after_post_updated() {
	static $skip_purge = false;

	if ( $skip_purge || ! function_exists( 'sg_cachepress_purge_cache' ) ) {
		return;
	}

	$skip_purge = true;

	add_action( 'shutdown', function () {
		sg_cachepress_purge_cache();
	} );
}

Changelog

Since 3.0.0 Introduced.

Where the hook is called

wp_insert_post()
post_updated
wp-includes/post.php 5255
do_action( 'post_updated', $post_id, $post_after, $post_before );

Where the hook is used in WordPress

wp-admin/includes/admin-filters.php 167
add_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_updated' ) );
wp-includes/default-filters.php 446
add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
wp-includes/default-filters.php 485
add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 );
wp-includes/default-filters.php 489
add_action( 'post_updated', 'wp_check_for_changed_dates', 12, 3 );