Hello guys, Can someone help me with a code change? I use this plugin in my wordpress site: https://github.com/lesterchan/wp-postratings But something is wrong with the thumbs voting. Here goes some tests that I did: With Values: -1, +1 I have talked with the plugin author but he is not offering support for this fix. He said: I'm not interested in the star rating, only up/down rating. I was checking the code in this file: https://github.com/lesterchan/wp-postratings/blob/master/wp-postratings.php And I have found this: if($post_ratings_score == 0 || $post_ratings_users == 0) { $post_ratings = 0; $post_ratings_average = 0; $post_ratings_percentage = 0; } else { $post_ratings = round($post_ratings_average, 1); $post_ratings_percentage = round((($post_ratings_score/$post_ratings_users)/$ratings_max) * 100, 2); } Code (markup): Is this the right code to fix this? Is it hard to found a solution?
I have checked the code and this wrong % showing I think is because of when user dislike the vote value increment by 1 added to the total for eg. at this: $post_ratings_percentage = round((($post_ratings_score/$post_ratings_users)/$ratings_max) * 100); PHP: $post_ratings_score=+2 like -2 dislike $post_ratings_users =total votes $ratings_max= 2 if 5 vote up and 1 down the this function calculate (8/6/2)*100) = 66 % but if we don't add 1 when dislike to total rated user then this function work good (8/5/2)*100)=80% but for fix this i still not find any solution. Am I close?
Pseudocode, not based on your real variables just verbose meanings. $percent = ($votes_up / ($votes_up + $votes_down)) * 100; This assumes $votes_down is a positive number, if negative subtract instead of add. Remember, - a - is a + You just need to divide the votes up by the total number of up and down.