最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Hook when category is added to post

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Oct 1, 2013 at 3:17 brasofilo 22.1k8 gold badges70 silver badges264 bronze badges asked Oct 1, 2013 at 2:42 stockholmuxstockholmux 1932 silver badges7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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)

  1. 暂无评论