• I’m looking for a plugin that counts the words for posts ONLY, not pages too. I’m having no luck. Anyone know of such a beast? Or if theres a way to do it without a plugin? Thanks.

Viewing 1 replies (of 1 total)
  • To limit only to posts your query would be:

    SELECT post_content FROM wp_posts WHERE post_type='post';

    Add a ‘WHERE’ clause to specify exactly which post you are interested in.

    To count the words, you would could use the php function ‘preg_split’, e.g.

    $wordcount = count(preg_split("/[\s,]+/",$one_post));

    preg_split uses a regular expression to decide about word boundaries. In this case, we’re saying, “split the text by any number of commas or space characters, which include ” “, \r, \t, \n and \f”. preg_split returns an array of all the words, which we immediately use to get the count.

    Tying this all together into something useful is left as an exercise for you to complete. 🙂 We will be grading on accuracy, completeness, spelling, and quality of the beer.

Viewing 1 replies (of 1 total)
  • The topic ‘Word Count For Posts Only’ is closed to new replies.