save_post
save-crudFires after a post is saved or updated
save_post runs after WordPress writes the post row. Use it for caches, sync, and derived data — and always guard against autosave, revisions, and infinite loops.
Signature
do_action( 'save_post', int $post_id, WP_Post $post, bool $update );Example
add_action( 'save_post', function( $post_id, $post ) {
if ( $post->post_type !== 'book' ) {
return;
}
delete_transient( 'book_list_' . $post_id );
}, 10, 2 );Common Use Cases
- Clear caches after post update
- Send admin email notifications
- Sync data to external APIs
- Auto-generate related records
- Queue heavy sync/recalculation work instead of running it inline on large tables


