Yesterday we had some problems with the database getting corrupted. As mentioned in a previous article What To Do When Your Wordpress Blog Vanishes, some of the database tables have been getting Overhead which can be fixed with repair table command in phpMyAdmin.
One of the tables that shows some overhead is wp_comments, which is the table containing comments to posts. Like most blogs, lots of spam comments are received everyday. The Akismet plugin catches most of it. But the spam posts still enter the comments database. Lately, some of the spam comments have been quite lengthy, several paragraphs. Sometimes the spam comments are long lists of hyperlinks. These long comments may be causing the high overhead in wp_comments.
So for now, we decided to disable comments to see if the database remains uncorrupted. The problem is wordpress doesn’t have an option to disable all comments.
How to Disable All Comments
The easiest way to disable comments is to close all comments on every post. Every post in the database has an “comment_status” field with value “open”, “closed” or “registered-only”. To close all comments we have to modify every post in the wordpress database. Here are the steps:
- Login to phpMyAdmin
- Select the wordpress database
- Select the SQL Tab
- Run the following SQL query:
UPDATE wp_posts p SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open'; - If you get an error, check the syntax and check the name of the wp_posts table
- Now comments should be closed on every post
Closing all the comments only closes comments on old posts. Each new post can set the comment_status field. The default setting is found under Discussion Settings/Default article settings. Check or uncheck the box “Allow people to post comments on the article” to set the default for new articles.
How to Enable All Comments
To enable comments on every post, use this SQL query:
UPDATE wp_posts p SET comment_status = 'open', ping_status = 'open' WHERE comment_status = 'closed';
Other Options
Closing all comments is rather harsh. If you want to allow comments but not have to deal with all the spam, there other options.
One is require that users be logged in before commenting. Under Discussion Settings/Other comment settings check the box “Users must be registered and logged in to comment”
Another is to check the box “Automatically close comments on articles older than xx days” Maybe consider closing comments after 7 days so there are only a limited number of articles to deal with.
Finally, to permanently disable comments, you can delete the wp-comments-post.php file.
Here is a good article that talks about many options for managing wordpress comments and pingbacks. There are some good SQL queries for managing discussions.
WordPress Discussion Management: Enable or Disable Comments and Pingbacks via SQL










