Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_updated filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
October 4, 2022
5 minutes read

post_updated filter

Fires once an existing post has been updated.

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

Description

This is an action hook, and it fires once an existing post has been updated. By using this hook, you can get the difference between $post_before and $post_after. It consists of three parameters: $post_ID, which is the post ID, $post_before, and $post_after. Try updating or adding a post, and you should see some output because this is when WordPress calls the hook function. To check for changes, compare the titles from the before and after post objects.

Here’s a basic example:


function weplugins_check_values($post_ID, $post_after, $post_before){
if( $post_after->post_title !== $post_before->post_title ) {
// do something
}
}
add_action( 'post_updated', 'weplugins_check_values', 10, 3 );

Parameters

  • $post_ID: (int) Post ID.
  • $post_after: (WP_Post) Post object following the update.
  • $post_before: (WP_Post) Post object before the update.

Live Examples

Example 1: Basic Usage

To run the hook, copy the example below:

    // run the action 
    do_action( 'post_updated', $post_ID, $post_after, $post_before); 
    

Example 2: Adding a Hook Callback

The following example is for adding a hook callback:

    // define the post_updated callback 
    function weplugins_action_post_updated( $post_ID, $post_after, $post_before ) { 
        // make action magic happen here... 
    }; 
             
    // add the action 
    add_action( 'post_updated', 'weplugins_action_post_updated', 10, 3 );  
    

Example 3: Removing a Hook Callback

To remove a hook callback, use the example below:

    // remove the action 
    remove_action( 'post_updated', 'weplugins_action_post_updated', 10, 3 ); 
    

Access Premium WordPress Plugins

Want more customization or have specific needs? Contact Us

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.