• Not sure if this is the best way to notify folks (particularly Alex) of this, but there’s a bug with Popularity Contest.

    I’ve been going back into some of my old posts on my blog and adding images to them. I noticed that as I did this the average popularity for the current month dropped precipitously. Unbeknownst to me, attachments have their own post entries in the db. Well, it’s known to me now. Anyway, as I was poking around the code and phpMyadmin I saw this bit of code used to query the DB for the monthly averages.

    $items = $wpdb->get_results("
    SELECT MONTH(p.post_date) AS month, AVG(pop.total) AS avg
    FROM $wpdb->posts p
    LEFT JOIN $wpdb->ak_popularity pop
    ON p.ID = pop.post_id
    WHERE YEAR(p.post_date) = '".$custom['y']."'
    GROUP BY month
    ORDER BY avg DESC
    ");

    Which includes the attachment “posts” in the averages.

    I’ve hacked my copy of popularity-contest with the following (only showing the pertinent line):

    WHERE YEAR(p.post_date) = '".$custom['y']."' AND p.post_type = 'post'

    It does the trick, but since I am not really an expert with the code base, it might not be the optimal solution.

    I don’t know if this or similar problems affect other portions of the reports. I suspect that the category averages are fine since attachment posts don’t go in a category.

    As a side note, I had been wondering why my post IDs stopped being sequential. Now I know.

  • The topic ‘Bug (and hack fix) in Alex King’s popularity-contest plugin’ is closed to new replies.