Fires when a post is transitioned from one status to another.
Parameters
$new_status
string- New post status.
$old_status
string- Old post status.
$post
WP_Post- Post object.
Source
do_action( 'transition_post_status', $new_status, $old_status, $post );
Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |
Please note that the name transition_post_status is misleading. The hook does not only fire on a post status transition but also when a post is updated while the status is not changed from one to another at all.
So if you wish to really only do stuff on status transition and not on regular post updates, you will need to (at least) start with a basic bailout like this:
For doing stuff when moving in and out (!) of published status only, use
Sometimes you only want to fire a callback when a post status is transitioned to ‘publish’, i.e. coming from some other status other than publish (published posts retain the publish status even when updating).
Only fire a callback when a post status is transitioned to publish
Example: Check if someone published a custom post type first time.
If you are looking to hook something on a specific post status change you can also use this hook
This could be used for two specific post status. For example if you are looking to hook something when a draft post is published you can use this hook like this,
Of course this opens up a possibility for so many things and you don’t have to keep relying on
transition_post_status
which runs even when post status are not changed.Status can be one of: publish, future, draft, pending, private