How to disable WordPress comments with MySQL

Owing to its blog origins, WordPress allows comments on most pages and posts by default. But for most sites, we don’t want comments on every page. When we started getting spam from supposedly blank pages, I discovered that the “comments” code had not been removed from all templates. Rather than revise the pages by hand, I started turning off comments one page at a time. But that was a chore.

Solution

A quick read in MySQL revealed that each post had its own control for comments. I wrote this query to disable comments across the board: update wp_posts set comment_status = 'closed' where post_status = 'publish'.

MySQL to English:

Warning

Be careful running this or any query on a live database unless you know what you’re doing.