我会用行动wp_footer
. 你可以做下面这样的事情。无论何时显示帖子,都不需要循环浏览所有帖子。只需将当前帖子分数添加到当前帖子的用户。
add_action(\'wp_footer\', \'wpse55725_update_user_score\');
function wpse55725_update_user_score(){
if( !is_singular(\'post\') )
return; // only run for single post
global $post;
$current_score = get_user_meta( $post->post_author, \'user_score\', true ); // get current score of the user
$score_points = get_post_meta( $post->ID, \'ratings_score\', true ); // score for the post
$score = $current_score + $score_points; // add the score to users current score
update_user_meta( $post->post_author, \'user_score\', $score); // save it
}
代码未测试。