This is the code I use to insert a list of taxonomy terms in a dedicated plugin category. On can also directly add the terms to the main post category.
// ************** Add taxonomy
$taxonomy_term = "my_term";
$taxonomy_category = "my_taxonomy_category";
if (null !==(get_the_ID())) {
if ( taxonomy_exists( $taxonomy_category ) ){
// if the tag doesn't exist
if ( ! $term = term_exists( $taxonomy_term, $taxonomy_category ) )
// insert it and get its id
$term = wp_insert_term($taxonomy_term, $taxonomy_category, array() );
// Create a list of plugin tags meant to be inserted into dedicated plugin category
$list_taxonomy_term .= $taxonomy_term . ", " ;
}
}
if ( $term && !is_wp_error( $term ) ) {
// Link terms to plugin dedicated category
wp_set_post_terms(get_the_ID(), $list_taxonomy_term, $taxonomy_category, true);
// Add plugin tags to the current WordPress post main taxonomy if we want so
# wp_set_post_tags(get_the_ID(), $list_taxonomy_term, 'post_tag', true);
}