How to mass/bulk delete all unapproved comments from wordpress

Do you have the problem of hundreds of comments building up on your WordPress site, we’ll the best solution is to check it regularly and delete the unwanted comments, just leaving the appropriate ones. However what happens if you go on holiday for a week and don’t check your blog, or if your forget to look at your comments for a few day (i.e. lost weekend down the pub) well you’ll probably find several hundred comments have built up in this time. Now you can delete these comments manually but this is time consuming. To make your life easier I’m going to go through some simple ways of deleting all unapproved comments while not using phpMyAdmin (as every other tutorial I’ve seen does use phpMyAdmin).

Just a quick warning before we start this method is pretty brutal, it is not a spam filter and these methods will delete all your comments weaver they are spam or not, so I only recommend using it when you have let your comments get out of hand and really don’t have time to go through manually, otherwise you might as well just disable comments in your WordPress settings.

I said at the beginning this tutorial is for those who don’t have phpMyAdmin, well as I’m nice I’ve included a quick video for the phpMyAdmin method at the bottom of the page. However if you don’t have phpMyAdmin installed there are a few other way you can delete all your unapproved comments. The easiest way is to have shell access to your box, if you don’t know just skip to the next step. All you need to do is access the box and run one MySQL statement, this can be done as follows:

mysql -u [USERNAME] -p -e "DELETE FROM wordpress.wp_comments WHERE comment_approved=0;" wordpress

And thats it all your unappoved comments will be delted saving your many hours of manualy deleting comments.

NEXT STEP: If you don’t have access to your shell and you don’t have phpMyAdmin installed there is another way to do this, you create a simple PHP page that deletes all comments and access it form your web browser. This should only really be used as a last resort as it will create a page that anyone can access that once opened will delete all your unread comments. This is fine to-do so long as your delete/restrict the page after you’ve finished. So let’s get started first open Notepad or some other html editor and create a page with the following code while adding your own username, password, and database name:


//Warning this page will delete all your WordPress comments once opened and can accessed by anyone so you should delete or restrict once used!

//Please replace the following with your details


$con = mysql_connect("localhost",$usrName,$usrPass);
if (!$con)
	die('Could not connect: Please check your usrName & usrPass settings');

mysql_select_db($usrDB, $con);

$result = mysql_query("DELETE FROM wp_comments WHERE comment_approved=0;");
if (!$result)
	die('Could not delete: Please check your usrDB setting');
	echo 'All unapproved comments now deleted';


Now you’ll need to save this page to something like wp-coment-remove.php then upload it to your site via your normal file transfer method (either ftp or via a http file uploader) once you have done this all you’ll need to do is access the page, so for this site I would go to the page , just substitute the-tech-tutorial for your sites address. Now that you have run this page, all your unapproved comments will be gone, hooray. Just remember that this page is a security risk because anyone can access it so either restrict is access once you’re done or delete the page.

As I promised here is the YouTube video showing how to do this with phpMyAdmin:

, , , , , , , ,

Comments are closed.