How do I do a global wordcount in MT?
November 27, 2005 9:22 AM   Subscribe

How do I get a global wordcount for every post made on my MT 2.66 blog?

MT Wordcount only seems to have tags for obtaining the number of words in each entry. I want to know the big number that is the total sum for all (558) entries on the blog.

Apparently MTWordStats used to do this, but the plugin's no longer available.

posted by Marquis to Computers & Internet (6 answers total)
This blog post suggest a hackish way using the Wordcount plugin you mentioned.
posted by chrismear at 9:47 AM on November 27, 2005

Response by poster: Hmm... Couldn't get that to work? Is there an interim step I'm missing between installing in my plugins directory and adding that code to one of my templates (and rebuilding)?
posted by Marquis at 12:11 PM on November 27, 2005

I'm not an MT expert by any means, but those steps seem to be all that is necessary. Have you got both bits of code in the template? Does anything funny appear on the page when you view it in your browser (like error messages, or raw code)?
posted by chrismear at 12:42 PM on November 27, 2005

Best answer: Do you need to do this once, or many times? If once, you can make a dumb template that looks like

<MTEntries lastn="999"><MTEntryBody></MTEntries>

to get a raw-text dump of all your entry text. Then just save the output from it and open it into your word-counting utility of choice
posted by adamrice at 1:09 PM on November 27, 2005

Best answer: How convoluted are you feeling today? If you have access to a shell command line and a command line version of PHP and are using mysql as an engine, the following horrendous command (all on one line) will give you a word count.
echo "select entry_text from mt_entry where entry_blog_id = yourblog_id;" | 
mysql -u mysql_username -h mysql_server_name -p mysql_database_name | 
php -r '$stdin = file_get_contents("php://stdin");print(str_replace(chr(92).chr(110),chr(10),strip_tags($stdin)));' | 
wc -w

I've bolded the items you'll need to customize.

mysql_username, mysql_server_name and mysql_database_name are the same things you're using in your MT configuration file.

yourblog_id is the mysql id number of the blog you want to do the word count on. If you don't know how to get this, the following command should give you the ids of all your blogs
echo "select blog_id, blog_name from mt_blog;" | 
mysql -u mysql_username -h mysql_servername -p mysql_database_name

posted by alana at 1:29 PM on November 27, 2005

Response by poster: Adamrice's silly (and in retrospect, obvious) hack worked a treat. Just under 225,000 words. Ca-razy. Thanks to everyone who took the time to help.
posted by Marquis at 3:57 PM on November 27, 2005

« Older Bring Home the Bacon   |   Does image theft worry you? Newer »
This thread is closed to new comments.