do_action( 'wp_insert_post', int $post_ID, WP_Post $post, bool $update )

Fires once a post has been saved.


Description Description


Parameters Parameters

$post_ID

(int) Post ID.

$post

(WP_Post) Post object.

$update

(bool) Whether this is an existing post being updated or not.


Top ↑

Source Source

File: wp-includes/post.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by leogermani

    Below is a basic example that will send an email every time a post or page is created or updated on your website. (copied from codex)

    function my_project_updated_send_email( $post_id, $post, $update ) {
    
    	// If this is a revision, don't send the email.
    	if ( wp_is_post_revision( $post_id ) )
    		return;
    
    	$post_url = get_permalink( $post_id );
    	$subject = 'A post has been updated';
    
    	$message = "A post has been updated on your website:\n\n";
    	$message .= $post->post_title . ": " . $post_url;
    
    	// Send email to admin.
    	wp_mail( 'admin@example.com', $subject, $message );
    }
    add_action( 'wp_insert_post', 'my_project_updated_send_email', 10, 3 );
    

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