“Anarchism, really stands for the liberation of the human mind from the dominion of religion; the liberation of the human body from the dominion of property; liberation from the shackles and restraint of government.” »» Emma Goldman


Using A Default Rating With WP-PostRatings Plugin

Posted on January 7, 2009
Stumble it!  |  Email This Post Email This Post   |  Print This Post Print This Post   |

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
Tags: , , , , , , , ,
Related Posts: » Filed Under: Blogging, Wonderful WordPress Wednesdays
» Trackback to: Using A Default Rating With WP-PostRatings Plugin


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


 

 

Comments

  1. nfl jerseys (2 comments) on 08.01.2009 at 01:20 (Reply)

    that is great

    nfl jerseyss last blog post..Buffalo Bills Donte Whitner White Replica Football Jersey #20

  2. [...] 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 [...]

  3. Repair company (1 comments) on 14.03.2009 at 21:17 (Reply)

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

  4. tiffany co (1 comments) on 09.08.2009 at 23:03 (Reply)

    Good post!Listed in My Favourite Now!And I couldn’t wait to share my wonderful tiffany co shopping experience.I have bought a tiffany bracelet at the price I never imaged.

Leave a comment

CommentLuv Enabled




  • Categories

  • Translator


  • Pages

Google