Last active
November 3, 2015 13:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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