do_action( 'transition_post_status', string $new_status , string $old_status , WP_Post $post )
Fires when a post is transitioned from one status to another.
Description Description
Parameters Parameters
- $new_status
-
(string) New post status.
- $old_status
-
(string) Old post status.
- $post
-
(WP_Post) Post object.
Source Source
File: wp-includes/post.php
Changelog Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
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
Expand full source codeCollapse full source code
Example: Check if someone published a custom post type first time.
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:
Expand full source codeCollapse full source code
For doing stuff when moving in and out (!) of published status only, use