This is the first time I've attempted to write an action hook.
My CPT has 4 categories. I'm trying to make WP automatically sends an email notification when the category is changed.
By change I mean: Let's say the post has a category of "cat1". The admin unselects cat1 and selects "cat2" and then clicks the "Update" button. I am not talking about overwriting or appending new categories to the list.
My code thus far:
add_action('set_object_terms','email_when_category_changes');
function email_when_category_changes(){
wp_mail( '[email protected]', 'Update on CI board', 'the category changed' );
}
The idea here being that the author will get an email notifying them that their post has been changed from cat1 to cat2.
The code above works in the sense that it sends an email when I click "Update". However, the problem is that it sends an email no matter what I do. Anytime I click "Update", whether anything changed or not, it sends the email.
I thought set_object_terms would only fire if the category was changed. Obviously I'm missing an important concept here. Can anyone help?