do_action( 'post_updated', int $post_ID, WP_Post $post_after, WP_Post $post_before )

Fires once an existing post has been updated.


Parameters

$post_ID

(int) Post ID.

$post_after

(WP_Post) Post object following the update.

$post_before

(WP_Post) Post object before the update.


Top ↑

More Information

Use this hook whenever you need to compare values before and after the post update.

This hook runs after the database update.

This hook pass up to 3 arguments, as follows:

  • $post_ID;
  • $post_after (post object after the update);
  • $post_before (post object before the update);

Top ↑

Source

File: wp-includes/post.php

View on Trac



Top ↑

Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Example migrated from Codex:

    Suppose we have a post named Original Title and we edit it to Edited Title. Let’s hook to post_updated to check what has changed:

    Let’s hook to post_updated to check what has changed:

    <?php
    function check_values($post_ID, $post_after, $post_before){
        echo '<b>Post ID:</b><br />';
        var_dump($post_ID);
    
        echo '<b>Post Object AFTER update:</b><br />';
        var_dump($post_after);
    
        echo '<b>Post Object BEFORE update:</b><br />';
        var_dump($post_before);
    }
    
    add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function
    ?>
    

    The Result then would be this:

    Post ID:
    int 1403
    Post Object AFTER update:
    object(WP_Post)[7722]
    public 'ID' => int 1403
    public 'post_author' => string '1' (length=1)
    public 'post_date' => string '2014-08-10 18:19:43' (length=19)
    public 'post_date_gmt' => string '2014-08-10 18:19:43' (length=19)
    public 'post_content' => string (length=0)
    public 'post_title' => string 'Edited Title' (length=12)
    public 'post_excerpt' => string (length=0)
    public 'post_status' => string 'publish' (length=7)
    public 'comment_status' => string 'closed' (length=6)
    public 'ping_status' => string 'closed' (length=6)
    public 'post_password' => string (length=0)
    public 'post_name' => string 'edited-title' (length=12)
    public 'to_ping' => string (length=0)
    public 'pinged' => string (length=0)
    public 'post_modified' => string '2014-08-10 19:41:46' (length=19)
    public 'post_modified_gmt' => string '2014-08-10 19:41:46' (length=19)
    public 'post_content_filtered' => string (length=0)
    public 'post_parent' => int 0
    public 'guid' => string 'http://localhost:8888/mysite/?post_type=test_post&p=1403' (length=67)
    public 'menu_order' => int 0
    public 'post_type' => string 'procedimentos' (length=13)
    public 'post_mime_type' => string (length=0)
    public 'comment_count' => string '0' (length=1)
    public 'filter' => string 'raw' (length=3)
    Post Object BEFORE update:
    object(WP_Post)[7724]
    public 'ID' => int 1403
    public 'post_author' => string '1' (length=1)
    public 'post_date' => string '2014-08-10 18:19:43' (length=19)
    public 'post_date_gmt' => string '2014-08-10 18:19:43' (length=19)
    public 'post_content' => string (length=0)
    public 'post_title' => string 'Original Title' (length=14)
    public 'post_excerpt' => string (length=0)
    public 'post_status' => string 'publish' (length=7)
    public 'comment_status' => string 'closed' (length=6)
    public 'ping_status' => string 'closed' (length=6)
    public 'post_password' => string (length=0)
    public 'post_name' => string 'original-title' (length=14)
    public 'to_ping' => string (length=0)
    public 'pinged' => string (length=0)
    public 'post_modified' => string '2014-08-10 19:41:14' (length=19)
    public 'post_modified_gmt' => string '2014-08-10 19:41:14' (length=19)
    public 'post_content_filtered' => string (length=0)
    public 'post_parent' => int 0
    public 'guid' => string 'http://localhost:8888/mysite/?post_type=test_post&p=1403' (length=67)
    public 'menu_order' => int 0
    public 'post_type' => string 'procedimentos' (length=13)
    public 'post_mime_type' => string (length=0)
    public 'comment_count' => string '0' (length=1)
    public 'filter' => string 'raw' (length=3)

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