您可以使用update_user_meta() 向用户的元字段添加信息,以及count_user_posts() 获取初始计数。
例如:
<?php
    add_action( \'new_to_publish\', \'wpse96358_author_count\' );
    add_action( \'draft_to_publish\', \'wps396358_author_count\' );
    function wpse96358_author_count() {
        global $post;
        // get initial count
        $single = true;
        $author_count = get_user_meta( $post->post_author, \'author_count\', $single );
        if ( strlen( $author_count ) > 0 ) {
            $author_count = intval( $author_count ); // make sure it\'s a number
            $author_count++; // increment by one
        } else {
            // the meta information isn\'t set, so we\'ll create it
            $author_count = count_user_posts( $post->post_author );
        }
        update_user_meta( $post->post_author, \'author_count\', $author_count );
    }
?>
NB
您最好咨询
Action Reference 以及
Post Status Transitions reference 看看哪种行动最适合你。我选择了
new_to_publish 和
draft_to_publish 但这取决于您希望何时进行更新。