If i understand the question correctly, you want that whenever a user adds a new post, all his/her previous posts should be deleted. I wonder why would you do that!! 🙂 But anyway, you can use this code.
add_action('save_post', 'delete_prev_posts_by_user', 10, 2 );
function delete_prev_posts_by_user( $post_id, $post ){
if( 'publish' == $post->post_status ){
$the_special_category_id = 1;//the id of the concerned category
$post_categories = wp_get_post_categories( $post_id );
$user = new WP_User( $post->post_author );
if( in_array( $the_special_category_id, $post_categories ) && 'contributor' == $user->roles[0] ){
$userposts = new WP_Query( array( 'author'=>$post->post_author, 'post__not_in'=>array( $post_id ), 'cat'=>$the_special_category_id ) );
if( $userposts->have_posts() ): while( $userposts->have_posts() ): $userposts->the_post();
//set the second parameter to false, to trash it rather than deleting permanently
wp_delete_post( get_the_ID(), true );
endwhile;
endif;
wp_reset_query();
}
}
}
You might want to change the user role though, according to ur requirement