do_action( "{$new_status}_{$post->post_type}", int $post_id , WP_Post $post , string $old_status )
Fires when a post is transitioned from one status to another.
Description
The dynamic portions of the hook name, $new_status and $post->post_type, refer to the new post status and post type, respectively.
Possible hook names include:
draft_postfuture_postpending_postprivate_postpublish_posttrash_postdraft_pagefuture_pagepending_pageprivate_pagepublish_pagetrash_pagepublish_attachmenttrash_attachment
Please note: When this action is hooked using a particular post status (like ‘publish’, as publish_{$post->post_type}), it will fire both when a post is first transitioned to that status from something else, as well as upon subsequent post updates (old and new status are both the same).
Therefore, if you are looking to only fire a callback when a post is first transitioned to a status, use the ‘transition_post_status’ hook instead.
Parameters
-
$post_idint -
Post ID.
-
$postWP_Post -
Post object.
-
$old_statusstring -
Old post status.
Source
File: wp-includes/post.php.
View all references
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Added $old_status parameter. |
| 2.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example Migrated from Codex:
The example below will send an email via wp_mail() to the post author when their article is published.
This WP hook helps you receive a slack notification every time a user saves a new post on your site. It uses your Slack webhook, username, and channel. It makes use of the PHP Slack library which can be downloaded via Composer to your themes directory.
Top ↑
Feedback
This will fire both when a user saves a new post and on updates. See the “Please note” section above. — By Iurié —
This example helps you log a published post to a text file in your (child) theme.