admin管理员组文章数量:1334866
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?
1 Answer
Reset to default 12You 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.
本文标签: categoriesHook when category is added to post
版权声明:本文标题:categories - Hook when category is added to post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742356907a2459596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论