What would be the nicest way to execute any code on post_status
change. In our case we need execute a function the moment the post_status
changes from draft
to publish
. As far as I can find there is nog action to do this.
1 Answer
Wrong search terms, already found it:
function on_all_status_transitions( $new_status, $old_status, $post ) {
if ( $new_status != $old_status ) {
// A function to perform actions any time any post changes status.
}
}
add_action( 'transition_post_status', 'on_all_status_transitions', 10, 3 );
-
1Also there is
post_updated
hook, which passes 3 arguments: post id, post after update and post before update https://core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/post.php#L3482 Commented Aug 10, 2016 at 8:07