{$new_status}_{$post->post_type} WordPress Action Hook
The {$new_status}_{$post->post_type} hook is triggered when a post of the type $post->post_type changes its status to $new_status. This hook can be used to perform an action when a post's status is changed. For example, you could use this hook to send an email notification or update a custom field in the post.
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_id
(int)Post ID.
- $post
(WP_Post)Post object.
- $old_status
(string)Old post status.
Source
File: wp-includes/post.php
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Added $old_status parameter. |
| 2.3.0 | Introduced. |