This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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 );
Want more customization or have specific needs? Contact Us
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.