WordPress: Open Comments More Selectively

There are a whole lot of tricks you can do with SQL to enable/disable comments.

If you want to turn them on for every single page, there’s this:

UPDATE wp_posts SET comment_status = 'open';

But me? I don’t like to blanket turn things on! I don’t like to have my pages allow comments, you see, so I use this instead:

UPDATE wp_posts SET comment_status = 'open' WHERE post_type = 'post';

I find this preferable than just opening it for everything (most people will tell you to omit the WHERE clause) since if you do that, you open comments for attachments, pages, CPTs and everything. Which I never want.

But what if you did open comments for everything and now you realized, oh snap!, you want to turn them off on attachment pages? That’s pretty easy:

UPDATE wp_posts SET comment_status = 'closed' WHERE post_type = 'attachment';

For more awesome SQL queries, check out Digging into WordPress – Easy Comment Management via SQL or the incredible Andrea’s How to Close Comments Across a MultiSite Network.

StudioPress Theme of the Month