A few of my blogs I’m maintaining suffer from a load of senseless one-word comments. I tried to find a simple way to delete all wordpress comments containing only one word at once. This is what I did:
First log into phpmyadmin or login via command line to your mysql database. For safety reasons you should create a backup before you delete anything…
You should test before deleting your comments with this query. It displays all comments (and their ids) which have only one word:
SELECT comment_ID, comment_content FROM wp_comments WHERE REPLACE( TRIM( comment_content ) , ' ', '' ) = TRIM( comment_content ) ;
If the output is ok, you can delete them with this query:
DELETE FROM wp_comments WHERE REPLACE( TRIM( comment_content ) , ' ', '' ) = TRIM( comment_content ) ;
INFO: You can add AND comment_approved = ’0′ if you want to delete only the pending comments.
That’s it. Neat and simple solution how to erase all (mostly senseless) comments with one word in wordpress, isn’t it?