Reset Drupal Comment Count

The following SQL code will recalculate comment counts for all nodes on your site.


update node_comment_statistics ncs set comment_count = (select count(*) from comment c where c.nid = ncs.nid) where 1=1

As with all these things, you should take a backup before running the script and run at your own risk. That said, it's basically safe to run and re-run this script whenever you like.

Rate this page: 
Your rating: None Average: 5 (1 vote)
Simon's picture

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Insert Google Map macro.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Insert Google Map macro.
  • You may use [view:name=display=args] tags to display views.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To prevent automated spam submissions leave this field empty.