Categorized under: Code, Geekiness, php

WordPress 2.0 not showing comment count

There was a problem with my site after I upgraded to wordpress 2.0. It was never showing an updated comment count. It turns out this had to do with the SpamKarma2 plugin. There is no easy way to update the comment count value. WordPress2 stores this comment_count value in the wp_posts table. Therefore I wrote a quick script that will update your site if you are having a similar problem.

Here is the script:

Just put it in a new file in your wp-admin directory – then visit it in your browser via the corresponding URL (if you follow the link save it as comment_count.php). After you visit the file it will just show you a blank page. However, it worked so make sure you delete it when you are done. To confirm it worked just view any post that wasn’t showing the correct comment_count and see that now it is.

To anyone familiar with SQL at all you may think my approach is a little unrefined and it is. What follows is the code I wanted to use – however It didn’t work with my version of mySQL. Honestly, I don’t know if works with any version of mySQL or if maybe I just have a minor syntax error.

I believe the first example will work for all versions of mySQL but the second version will only work with MySQL 4.1 or later.

Comments

  1. [...] Telleverket for kommentarer er nå fikset, slik at artiklenes head nå forteller det riktige antall kommentarer på hver enkelt artikkel. Feilen skyldtes antakelig en bug i masseredigeringsmodus av kommentarer. En fiks finner du her. Og nok en gang var det min venn Rune som var den reddende engelen. [...]

  2. Great! I had already pushed through this problem and done the same thing, though yours is more refined. Our code doesn’t match, but it’s cool to see we were working the same problem the same way.


    Olaf Gradin
    March 20th, 2006
  3. Well I am glad I could provide validation to your technique then ;O)
    cheers,
    Bill


    Bill
    March 20th, 2006
  4. I used it in conjunction with this nucleus 2 wordpress convertor.
    http://mamchenkov.net/wordpress/2005/04/26/nucleus2wordpress/
    Worked brilliantly. Cheers.
    Ken


    Ken
    May 14th, 2006
  5. excellent. I’m always happy to hear I was able to help someone.


    Bill
    May 14th, 2006
  6. [...] Anyway, the only way to fix the comments problem is to rebuilt the comment counts on the posts “manually” I found a nice sample bit of code that does exactly that.. Now I jsut had to apply it to 20 blogs… hey wait a minute, I might have a solution to that. [...]

  7. [...] How I fixed the comment count in my blog. [...]

  8. [...] The comment counters of my articles have been messed up. I’ve noticed this thing several months and it’s probably related to WordPress updates. I set the counters manually within PhpMyAdmin for the first time it happened, but I got pretty pissed off when it already happened later so I decided to fix this mess. I’ve googled around for the solution and found a pretty good script to solve the problem which was a bit buggy and incomplete, so I fixed it. [...]

  9. I would add “AND comment_approved = ’1′” to the WHERE clause. Otherwise, anything that’s not approved or that’s spam will be included in the count.


    Mike
    January 11th, 2008
  10. thanks for the extra information Mike!


    Bill
    January 11th, 2008
  11. The script is no longer displaying, but can be found here: http://rawlinson.us/blog/sourcecode/431/comment...


    Sarah Lewis
    September 29th, 2009
  12. [...] So, another person developed a fix: http://rawlinson.us/blog/articles/wordpress-20-not-showing-comment-count/ [...]

  13. I’m always happy to hear I was able to help someone.


    Akkus
    August 18th, 2010

blog comments powered by Disqus
RSSSubscribe to my feed now.