I have custom post created at user's registration. There is also a custom taxonomy ('connection1') created. I need to add this post to that taxonomy.
Post is added fine. Taxonomy is added no problem as well. But for some reason, post is not added to the taxonomy
$user = new WP_User( $user_id );
$user->set_role( 'participation' );
$my_cptpost_args = array(
'post_title' => 'user-'.$user_id,
'slug' => $user_id,
'post_status' => 'publish',
'post_type' => 'profile'
);
$cpt_id = wp_insert_post( $my_cptpost_args, $wp_error);
wp_insert_term($user_id,'connection1');
$term_id = term_exists( $user_id, 'connection1' );
wp_set_post_terms($cpt_id , array( $term_id ), 'connection1' );