Script doesn’t trash custom post types. Instead it duplicates the post and generate new versions in the trash

The $id variable is never set. Use this instead:

wp_trash_post( $postid );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)