Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Last active November 3, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lynt-smitka/bb5706bc0303553477bc to your computer and use it in GitHub Desktop.
Save lynt-smitka/bb5706bc0303553477bc to your computer and use it in GitHub Desktop.
WP mu-plugin replaces "Highest Score By Time Range" in WP-PostRatings for titulkomet.cz
<?php
/*
Plugin Name: WP-Ratings Score correction for titulkomet.cz
Description: Displays the best posts in chosen timerange
Author: Vladimir Smitka
Version: 1.0
Author URI: http://lynt.cz
*/
function get_highest_score_range($time = '1 day', $mode = '', $limit = 10, $chars = 0, $display = true) {
global $wpdb;
$min_time = date('Y-m-d H:i:s',strtotime('-'.$time, current_time('timestamp')));
$output = '';
if(!empty($mode) && $mode != 'both') {
$where = "$wpdb->posts.post_type = '$mode'";
} else {
$where = '1=1';
}
$temp = stripslashes(get_option('postratings_template_highestrated'));
$highest_score = $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 $wpdb->posts.post_date >= '$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_average DESC, ratings_score DESC LIMIT $limit");
if($highest_score) {
foreach ($highest_score as $post) {
$output .= expand_ratings_template($temp, $post, null, $chars, false)."\n";
}
} else {
$output = '<li>'.__('N/A', 'wp-postratings').'</li>'."\n";
}
if($display) {
echo $output;
} else {
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment