do_action( "{$new_status}_{$post->post_type}", int $post_id, WP_Post $post )

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


Description Description

The dynamic portions of the hook name, $new_status and $post->post_type, 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_{$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 Parameters

$post_id

(int) Post ID.

$post

(WP_Post) Post object.


Top ↑

Source Source

File: wp-includes/post.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by tdatu
    add_action('publish_post', 'send_notification');
    
    function send_notification($id, $post_obj){
    	
    	//Assemble the message
    	$msg = 'Hi, a new post has been published. Here is the content:';
    	$msg .= $post_obj->post_content;
    	
    	//Send the notification
    	wp_mail('[email protected]', $post_obj->post_title, $msg);
    }
    

You must log in before being able to contribute a note or feedback.