Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Perform Comment Recount for WordPress

Run from the command line and uncomment line #2 if your mysql adapter is installed via RubyGems. Fast as hell.

   1  
   2  #!/usr/bin/ruby
   3  #require 'rubygems'
   4  require 'mysql'
   5   
   6  db = Mysql.real_connect("host", "username", "password", "database")
   7  ids = db.query("SELECT `ID` FROM `wp_posts` WHERE 1")
   8   
   9  ids.each_hash do |post|
  10    id = post['ID']
  11    num = 0
  12    comments = db.query("SELECT COUNT(1) FROM `wp_comments` WHERE `comment_post_ID`='#{id}' AND `comment_approved`='1';")
  13    comments.each {|x| num = x[0]}
  14    up = db.query("UPDATE `wp_posts` SET `comment_count`='#{num}' WHERE `ID`='#{id}';")
  15  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS