rendered paste body$results = $wpdb->get_results("SELECT DISTINCT(post_ID) FROM `newviewer_comment_votes`", ARRAY_A);foreach ($results as $result) { $postID = $result['post_ID']; $posts = $wpdb->get_results("SELECT * FROM `newviewer_comment_votes` WHERE `post_ID` = $postID", ARRAY_A); $totalVotes = count($posts); $sum = 0; foreach ($posts as $post) { $sum += $post['vote']; } $currentVote = round($sum / $totalVotes, 1); //echo "UPDATE `newviewer_posts` SET `total_vote` = $totalVotes, `post_current_vote` = $currentVote WHERE ID = $postID"; $wpdb->query("UPDATE `newviewer_posts` SET `total_vote` = $totalVotes, `post_current_vote` = $currentVote WHERE ID = $postID");}