We Recommend

Beginning XML Beginning XML
The perfect resource for beginning XML programmers, this guidebook shows you what XML is, how to use it, and what technologies surround it. The authors build on the strengths of previous editions while covering the latest changes in the XML landscape such as XQuery, RSS and Atom, and Ajax.


Posted By

breakerjump on 05/14/08


Tagged

textmate wordpress ruby comments


Versions (?)


WordPress Comment Recount via Ruby


Published in: Other 


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

Report this snippet 

You need to login to post a comment.