Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress post save/edit post hook

I'm looking for a admin hook for posts that gets fired after the post has been saved. The problem: the save_post does not contain the already changed data to the post object. The new changes can only be found in the $_POST array. But I need a way to update the permalink to a external API once the post_name changes. But it will not work since the $post object is still the old one before the save action.

like image 830
setcookie Avatar asked Nov 24 '25 14:11

setcookie


1 Answers

You should be able to hook in after the post has been updated using the priority argument (set to 20 in this example):

add_action( 'save_post', 'your_function', 20, 1 );
function your_function( $post_id ) {
    // this should be the updated post object 
    $post = get_post( $post_id );
}
like image 53
locomo Avatar answered Nov 27 '25 12:11

locomo