I want to check if the title of the post has changed and do some stuff if it did.
I thought of using the post_updated hook, the codex says "Use this hook whenever you need to compare values before and after the post update.", but i can't figure out how to use the before and after arguments.
function check_values($post_ID, $post_after, $post_before){
echo 'Post ID:';
var_dump($post_ID);
echo '<br>Post Object AFTER update:';
echo '<pre>';
print_r($post_after);
echo '</pre>';
echo '<br>Post Object BEFORE update:';
echo '<pre>';
print_r($post_before);
echo '</pre>';
}
add_action( 'post_updated', 'check_values', 10, 3 );
and i'm echoing it echo check_values($post->ID, get_post(),get_post());
inside a metabox.
Currently I'm getting the same values.
If i echo check_values();
I get missing argument error and on echo check_values($post_ID, $post_after, $post_before)
i get NULL.
How can i get the values before and after the update?
Update
function check_values($post_ID, $post_after, $post_before){
if ($post_before->post_title != $post_after->post_title) {
// do stuff
}
}
add_action( 'post_updated', 'check_values', 10, 3 );
$post_before
and$post_after
likeif ($post_before->post_title != $post_after->post_title) { //title changed! }
echo check_values($post->ID, get_post(),get_post());
inside a metabox... this function is an action when a post is saved or updated.. you need something else if you want to check the title of the post