你可以使用动作钩save_post_{post_type}
, 因此,对于帖子类型“post”(博客帖子),它是:save_post_post
. 有关更多信息,请参阅codex.
add_action( \'save_post_post\', \'sw150216_save_reading_time\', 10, 3);
function sw150216_save_reading_time( $post_id, $post, $update ) {
$reading_time = estimated_reading_time( $post );
if ( $update ) {
update_post_meta ( $post_id, \'reading_time\', $reading_time );
} else {
add_post_meta( $post_id, \'reading_time\', $reading_time, true );
}
}