How to change post status in hook?

You get the full post object as a second parameter on save_post. Use it to change the status just like the following code.

add_action( 'save_post', 'wpse_78351_status', 10, 2 );

function wpse_78351_status( $post_ID, $post )
{
    remove_filter( current_filter(), __FUNCTION__ );

    if ( 'trash' !== $post->post_status ) //adjust the condition
    {
        $post->post_status="draft"; // use any post status
        wp_update_post( $post );
    }
}

See this answer for a list of post statuses.

Leave a Comment

tech