钩入save_post
, 数一数单词,并更新post meta字段。
未测试的示例代码:
add_action( \'save_post\', \'wpse_73563_save_word_count\', 10, 2 );
function wpse_73563_save_word_count( $post_ID, $post )
{
if ( ! current_user_can( \'edit_\' . $_POST[\'post_type\'], $post_ID ) )
{
return FALSE;
}
$count = t5_word_count( $post->post_content );
update_post_meta( $post_ID, \'_word_count\', ( 200 > $count ? 2 : 1 ) );
}