Jan 072009
 
Part of the Wonderful WordPress Wednesdays Series - Previous in series         Next in series

Welcome to the eleventh installment of my Wonderful WordPress Wednesday series. Today’s lesson is a quick little hack for one of my favorite plugins: WP-PostRatings (by the irrepressible Lester ‘GaMerZ’ Chan) which adds an AJAX rating system for your WordPress blog’s posts.  I don’t use it here on Philaahzophy, but it’s a vital part of several other blogs that I manage.

My problem occurred on my amusement park and roller coaster video blog where I also use a plugin (that I previously wrote about) to schedule posts for future dates.  You see, I’ve noticed that people are far more likely to actually rate a post if others have already done so.  Therefore I was visiting each post after it was published and rating it myself.  This can become bothersome since I schedule posts on that blog days or even weeks in advance.  What I needed was for the WP-PostRatings plugin to add a default rating score to every post as it was published.  Luckily, with a little poking around and some help from more PHP-knowledgeable friends I was able to come up with a solution.

Simply navigate to Plugins > Editor > WP-PostRatings in your WordPress admin area and scroll down to lines 763-766 which read as follows:

add_post_meta($post_ID, 'ratings_users', 0, true);
add_post_meta($post_ID, 'ratings_score', 0, true);
add_post_meta($post_ID, 'ratings_average', 0, true);

Now, change the values in each variable to reflect your default ratings. For example, to have each post be published with a single rating and a score of 4 you would change the code to appear as follows-

add_post_meta($post_ID, 'ratings_users', 1, true);
add_post_meta($post_ID, 'ratings_score', 4, true);
add_post_meta($post_ID, 'ratings_average', 4, true);

You can set whatever default ratings you like, but make sure that your math works out or you’re likely to get some type of error.

  • ratings_users refers to the number of different people that have entered their rating
  • ratings_score is the total value of all the ratings thus far added together
  • ratings_average is the current score of the post

So you’ll want to make sure that ratings_score divided by ratings_users is equal to ratings_average.  If you’re worried about the math, just use the values in the example above and all of your posts will publish with a rating of 4 granted by a single user (you do think all of your posts are worthy of at least 4 out of 5 stars, don’t you?).

As always, if you have any difficulty with this tip, questions about using WordPress more effectively, suggestions for future articles in this series, or just want to say ‘Hi’ or ‘Thanks’, comments are always very much appreciated!  And if you found this post useful or informative, please consider adding it to your choice  social bookmarking sites (StumbleUpon, Digg, Reddit, etc).

Part of the Wonderful WordPress Wednesdays Series - Previous in series        Next in series

  6 Responses to “Using A Default Rating With WP-PostRatings Plugin”

  1. […] amazing WP-PostRatings plugin to allow visitors to rate your posts, then you’ll probably find Using A Default Rating With WP-PostRatings Plugin, posted at Philaahzophy very […]

  2. Is there a way to locate someone locally to try this?

  3. I used the plugin 2 times!
    Testsieger Rechtsschutzversicherung
    Private Rechtsschutzversicherung Vergleich

  4. I absolutely admire the author for attributing their time for this astounding article. Surely many readers can benefit on this topic. Thank you.

  5. Superb writing! I never have seen such a peace like this one! Awesome! Will keep reading you other articles!

  6. alternatively you could install a rating plugin, such as the Purple Heart Rating Plugin, see here: http://wp-buddy.com/products/p.....ss-plugin/

  7. Thanks , I have recently been looking for info about this subject for ages and yourfs iis thhe greatest I’ve discovered so
    far. However, what in regards to the bottom line?
    Are you sure about the supply?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)