我使用一个名为Post Word Count 要合计我整个网站上已发布的单词总数。。。再说一遍,我是唯一的作者,所以这是一个非常简单的例子。但您可以从这个插件开始,添加一个过滤器,根据作者的ID更改查询。基本上:
function post_word_count_by_author($author = false) {
global $wpdb;
$now = gmdate("Y-m-d H:i:s",time());
if ($author) $query = "SELECT post_content FROM $wpdb->posts WHERE post_author = \'$author\' AND post_status= \'publish\' AND post_date < \'$now\'";
else $query = "SELECT post_content FROM $wpdb->posts WHERE post_status = \'publish\' AND post_date < \'$now\'";
$words = $wpdb->get_results($query);
if ($words) {
foreach ($words as $word) {
$post = strip_tags($word->post_content);
$post = explode(\' \', $post);
$count = count($post);
$totalcount = $count + $oldcount;
$oldcount = $totalcount;
}
} else {
$totalcount=0;
}
return number_format($totalcount);
}
此函数将返回该作者发布的所有单词的总数(基于作者ID)。如果不指定作者ID,它将返回所有已发布单词的计数。这不会计算帖子修订、草稿或日程安排帖子,只计算用户当前可见的帖子。
免责声明,我尚未对此进行测试,但它基于原始的Post Word Count插件,应该可以正常工作