Support » Plugin: NextGEN Gallery Voting » A problem with filtering top voted images

  • Resolved lagdonkey


    I REALLY hate to be a bother yet again, but since you were so helpful with my other issues, and since I feel I’ve reached the extent of what googling and fiddling can get me, I’ll post my problem here hoping you’ll save me.

    What I am looking to achieve, is to create a function that shows the top voted images. I came across this thread:

    And after reading through it all, I went with the sollution you provided in one of your last posts. This is the code I’m using (Slightly modified):

    Now I have 2 problems. First, this seems create blank entries in the list. And I mean completely blank, none of the data that should be in the array for that entry is there, it all comes back empty. The other entries that it displays, all expected data is there.

    The second problem I have, is that if I order by avg, it seems to make the list randomly. The image that has 52 likes and 2 dislikes, shows up AFTER other entries that have only 1-3 likes and 0-1 dislike. I did the math myself, and it seems like AVG should be likes * 100 / total # of votes, but it doesn’t seem to be sorting them that way.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Quick update, for problem 2. It seems like YOUR code somehow finds images that were in my galleries, and then I deleted. Seems your plugin doesn’t erase vote results when images are deleted, since it’s still passing the PIDS for images that no longer exist (nor does that particular PID).

    When I pass the info into my own array, it seems to be filter out since:

    $top_list[] = nggdb::find_image($val->pid);

    passes no data, since it’s searching the actual database for a PID that doesn’t exist.

    Plugin Author shauno


    Hi again lagdonkey

    That code is pretty old. You are right that it will find images that have votes, that have since been deleted. It also was to get the images with the highest average ratings (like out of 5 stars). All ‘likes’ are seen as 100/100. So and image with 10 likes has the smame average as an image with 2 likes. They both average 100 🙂

    I updated the ‘top voted’ screen logic to work better with ‘likes’ a long time ago, so here is that logic you can use in your code now:

    SELECT, v.criteria_id, SUM( AS total, AVG( AS avg, MIN( AS min, MAX( AS max, COUNT( AS num, p.*
    FROM wp_nggv_votes AS v LEFT JOIN wp_ngg_pictures AS p ON =
    WHERE > 0
    GROUP BY, v.criteria_id
    ORDER BY avg DESC, num DESC

    Hope that helps

    Yeah, that works perfectly. In fact, looking at the oode, I think that the old code I was working would have worked well as well (minus the blank entries showing up).

    I guess the piece I was missing, was that even with the OLD code it was sorting by average correctly, I was just wrongly assuming that an image with 52 likes and 2 dislikes should score higher than a picture with 2 likes and no dislikes. Of course this isn’t the case since the latter will always be 100, whereas the former will always be <100. I think I have to stop trying to code for long periods of time without stopping for breaks because sometimes I tend to overlook the simplest details.

    Yet again, I owe you many thanks for your help :).

    Plugin Author shauno


    No problem. If you want, you can leave a review 🙂

    There also is a premium add-on available that extends a couple of the features that might be worth checking out.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘A problem with filtering top voted images’ is closed to new replies.