WordPress Comment Recount via Ruby


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.