这是Stephen答案的更新,基于新的get\\u terms\\u by function,并假设我们知道需要什么样的分类法。
add_action(\'set_object_terms\',\'save_terms\',10,6);
function save_terms($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) {
//Assuming we only want terms from specific taxonomy
//If not simply remove this conditional
$our_taxonomy = \'categories\';
if($taxonomy == $our_taxonomy){
//Added terms are specified terms, that did not already exist
$added_tt_ids = array_diff($tt_ids, $old_tt_ids);
if ($append) {
//If appending terms - nothing was removed
$removed_tt_ids = array();
} else {
//Removed terms will be old terms, that were not specified in $tt_ids
$removed_tt_ids = array_diff($old_tt_ids, $tt_ids);
}
/* Note problem 2 by Stephen, we would preferably like the term objects / IDs,
Currently we have the taxonomy term IDs */
foreach($added_tt_ids as $term){
$added_terms[] = get_term_by( \'term_taxonomy_id\',$term,$taxonomy);
}
foreach($removed_tt_ids as $term){
$removed_terms[] = get_term_by( \'term_taxonomy_id\',$term,$taxonomy);
}
//$added_terms contains added term objects
//$removed_terms contains removed term objects
}
}