Skip to content

Instantly share code, notes, and snippets.

@thenbrent
Created May 30, 2012 01:56
Show Gist options
  • Select an option

  • Save thenbrent/2832609 to your computer and use it in GitHub Desktop.

Select an option

Save thenbrent/2832609 to your computer and use it in GitHub Desktop.
Count all words in all the posts of a WordPress site via MySQL
SELECT SUM(LENGTH(`post_content`) - LENGTH(REPLACE(`post_content`,' ',''))+1)
FROM `wp_posts`
@scribu

scribu commented May 30, 2012

Copy link
Copy Markdown

Wouldn't it be faster to calculate the number of spaces and then add 1?

@thenbrent

Copy link
Copy Markdown
Author

Yes, assuming people don't do the old fashion "double space after a period". I only needed a general idea of word count (up to around 20% variation is fine) so either would be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment