
有时候,我们要在发布、编辑自定义文章类型时,做一些动作,比如发送邮件通知,发送短信通知,给这个用户添加一些标记,比如给他加钱、加积分等等。那么可以用以下几种方法实现:
1、借用save_post
add_action('save_post','save_post_callback'); function save_post_callback($post_id){ global $post; if ($post->post_type != 'MY_CUSTOM_POST_TYPE_NAME'){ return; } //if you get here then it's your post type so do your thing.... }
2、其实也时save_post的一种变形save_post_{$post_type}
add_action( 'save_post_my_post_type', 'wpse63478_save' ); function wpse63478_save(){ //save stuff }
还没有评论,来说两句吧...