-2

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.

0

1 Answer 1

1

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 );

https://codex.wordpress.org/Post_Status_Transitions

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.