All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.


Author Topic: get_most_rated_current_month ?  (Read 191 times)

0 Members and 1 Guest are viewing this topic.

Offline Lightman

  • Newbie
  • *
  • Posts: 2
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: default
get_most_rated_current_month ?
« on: 02 February 2010, 09:33 »
Hi, firstly, thanks for the great plugins!

I'm using WP-PostRatings with success and I was wondering if there is a way to show the most rated in current month. I used get_most_rated_range('1 month') but I think it shows posts in the last 30 days, not in current month.

Thanks.

Offline Lightman

  • Newbie
  • *
  • Posts: 2
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: default
Re: get_most_rated_current_month ?
« Reply #1 on: 02 February 2010, 10:56 »
Ok I think this is it:

Code: [Select]
### Function: Display Most Rated Page/Post in Current Month
if(!function_exists('get_most_rated_month')) {
function get_most_rated_month($mode = '', $limit = 10, $chars = 0, $display = true) {
global $wpdb, $post;
$ratings_max = intval(get_option('postratings_max'));
$ratings_custom = intval(get_option('postratings_customrating'));
$min_time = "UNIX_TIMESTAMP(DATE_FORMAT(NOW() ,'%Y-%m-01 00:00:00'))";
$output = '';
if(!empty($mode) && $mode != 'both') {
$where = "$wpdb->posts.post_type = '$mode'";
} else {
$where = '1=1';
}
if($ratings_custom && $ratings_max == 2) {
$order_by = 'ratings_score';
} else {
$order_by = 'ratings_average';
}
$temp = stripslashes(get_option('postratings_template_mostrated'));
$most_rated = $wpdb->get_results("
SELECT
COUNT($wpdb->ratings.rating_postid) AS ratings_users,
SUM($wpdb->ratings.rating_rating) AS ratings_score,
ROUND(((SUM($wpdb->ratings.rating_rating)/COUNT($wpdb->ratings.rating_postid))), 2) AS ratings_average,
$wpdb->posts.*
FROM $wpdb->posts
LEFT JOIN $wpdb->ratings ON $wpdb->ratings.rating_postid = $wpdb->posts.ID
WHERE
rating_timestamp >= $min_time AND
$wpdb->posts.post_password = '' AND
$wpdb->posts.post_date < '".current_time('mysql')."' AND
$wpdb->posts.post_status = 'publish' AND
$where
GROUP BY $wpdb->ratings.rating_postid
ORDER BY ratings_users DESC, $order_by DESC
LIMIT $limit
");
if($most_rated) {
foreach ($most_rated as $post) {
$output .= expand_ratings_template($temp, $post->ID, $post, $chars)."\n";
}
} else {
$output = '<li>'.__('N/A', 'wp-postratings').'</li>'."\n";
}
if($display) {
echo $output;
} else {
return $output;
}
}
}