您需要首先致电
get_object_terms才能获得已经存在的所有条款.
更新代码
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;
}