您可以使用pre_post_update
动作钩如下:
add_action(\'pre_post_update\',\'post_updating_callback\');
function post_updating_callback($post_id){
global $post;
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ($post->post_status == "publish"){
//do update stuff here.
}
}
更新时间:
而不是wp_insert_post()
使用wp_update_post
像这样:
//first get the original post
$postarr = get_post($post_id,\'ARRAY_A\');
//then set the fields you want to update
$postarr[\'post_title\'] = "new title";
$postarr[\'post_content\'] = "new edited content";
$post_id = wp_update_post($postarr);
这样,您只需指定已更新的字段,而不用担心原始帖子类型之类的问题。