<new_status>_<post_type>

Fires when a post is transitioned from one status to another.

Description

do_action( '<new_status>_<post_type>', (int) $post_id, (WP_Post) $post ); 

The dynamic portions of the hook name refer refer to the new post status and post type, respectively.

Please note: When this action is hooked using a particular post status (like 'publish', as publish_), 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 hook instead.

Parameters (2)

0. $post_id (int)
The post id.
1. $post (WP_Post)
Post object.

Usage

To run the hook, copy the example below.
  1. // run the action 
  2. do_action( '{$new_status}_{$post_type}', $post_id, $post ); 
The following example is for adding a hook callback.
  1. // define the <new_status>_<post_type> callback 
  2. function action_new_status_post_type( $post_id, $post ) { 
  3. // make action magic happen here... 
  4. }; 
  5.  
  6. // add the action 
  7. add_action( "{$new_status}_{$post_type}", 'action_new_status_post_type', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the action 
  2. remove_action( "{$new_status}_{$post_type}", 'action_new_status_post_type', 10, 2 ); 

Defined (1)

The action is defined in the following location(s).

/wp-includes/post.php  
  1. do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );