I’m still getting an error in my code. To figure out exactly what is wrong in the code, I deleted, the comment section in the plugin so that I could figure out exactly what line I’m getting an error on. Here it is:
global $wpdb, $tableposts, $id;
And here is the code for the plugin that I have now:
<?php
function post_word_count() {
????????global $wpdb, $tableposts, $id;
????????$post = $wpdb->get_results("SELECT post_content FROM $tableposts WHERE id=$id");
????????$words = strip_tags($post[0]->post_content);
????????$words = explode(' ', $words);
????????$counting = count($words);
????????$counting = $counting;
????????$wordcount = number_format($counting);
????????echo $wordcount;
}
function total_word_count() {
????????global $wpdb, $tableposts;
????????$words = $wpdb->get_results("SELECT post_content FROM $tableposts WHERE post_status = 'publish'");
????????foreach ($words as $word) {
????????????????$post = strip_tags($word->post_content);
????????????????$post = explode(' ', $post);
????????????????$count = count($post);
????????????????$totalcount = $count + $oldcount;
????????????????$oldcount = $totalcount;
????????????????$finalcount = number_format($totalcount);
????????}
????????echo $finalcount;
}
function out_of_count() {
????????global $wpdb, $tableposts, $id;
????????$post = $wpdb->get_results("SELECT post_content FROM $tableposts WHERE id=$id");
????????$words1 = strip_tags($post[0]->post_content);
????????$words1 = explode(' ', $words1);
????????$counting = count($words1);
????????$counting = $counting;
????????$wordcount = number_format($counting) . " " . ($counting==1 ? "word" : "words");
????????$words = $wpdb->get_results("SELECT post_content FROM $tableposts WHERE post_status = 'publish'");
????????foreach ($words as $word) {
????????????????$post2 = strip_tags($word->post_content);
????????????????$post2 = explode(' ', $post2);
????????????????$count = count($post2);
????????????????$totalcount = $count + $oldcount;
????????????????$oldcount = $totalcount;
????????????????$finalcount = number_format($totalcount);
????????}
????????echo "$wordcount of $finalcount words";
}
?>