How to change post status from publish to draft using hook in wordpress?

In your functions.php :

add_action('publish_post', 'check_user_publish', 10, 2);

function check_user_publish ($post_id, $post) {

    if($post_id == 1){
    $query = array(
        'ID' => $post_id,
        'post_status' => 'draft',
    );
    wp_update_post( $query, true );

    }

}

Leave a Comment