You need to first call get_object_terms to get all the terms that exist already.
function addTerm($id, $tax, $term) {
$term_id = is_term($term);
$term_id = intval($term_id);
if (!$term_id) {
$term_id = wp_insert_term($term, $tax);
$term_id = $term_id['term_id'];
$term_id = intval($term_id);
}
// get the list of terms already on this object:
$terms = wp_get_object_terms($id, $tax)
$terms[] = $term_id;
$result = wp_set_object_terms($id, $terms, $tax, FALSE);
return $result;
}
Add comment