With:
wp_add_object_terms( $cpt_dates_post_ID, intval($manifestation_insert_id), 'cpt_dates_postID');
You’re actually saying “Add a cpt_dates_postID
term with ID intval($manifestation_insert_id)
to the CPT with ID $cpt_dates_post_ID
“.
That won’t work, because intval($manifestation_insert_id)
is the ID of:
another post (from another CPT, freshly inserted with […]
Not the ID of an existing $cpt_dates_post_ID
term entry.
The reason why these 2 work:
wp_add_object_terms( $cpt_dates_post_ID, strval($another_post_id), 'cpt_dates_postID');
wp_add_object_terms( $cpt_dates_post_ID, 'foo', 'cpt_dates_postID');
Is because you’re passing a string as the 2nd parameter. In that case, WordPress will create a new term of type cpt_dates_postID
with name strval($another_post_id)
or foo
.
Off the top of my mind, you could do this instead:
// Create the term entry
$term_ids = wp_insert_term( strval( $another_post_id ), 'cpt_dates_postID' );
// Assign it to your post
wp_add_object_terms( $cpt_dates_post_ID, $term_ids[0], 'cpt_dates_postID');