7

I'm trying to do something when a category is added to post and saved. I thought that using the save_post hook would have registered when a category is added to a post, but it doesn't appear to.

When I edit a post and do nothing but change the categories for the post, I don't get the save_post hook fired (editing the title, body, etc fires the save_post hook successfully). Is there another way to use add_action/add_filter to detect when a category is added to a post?

1 Answer 1

12

You may want to try:

do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids);

You can find it under this Docs and the action is located at wp-includes/taxonomy.php

add_action('set_object_terms','wpse5123_set_object_terms',10,4);

function wpse5123_set_object_terms($object_id, $terms, $tt_ids, $taxonomy){
       if($taxonomy == 'category'){
           echo '<pre>';
           print_r($terms);
           echo '</pre>';
           exit;
       }
}

The code above isn't tested but I think you get the point.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.