Forums

Word Count For Posts Only (2 posts)

  1. poe
    Member
    Posted 3 years ago #

    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.

  2. Ogre
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.