I’m cleaning up an old, controversial blog entry and I need to remove all the comments from the post.
Surprisingly, I can’t find a way to do this within the existing WordPress (3.0.4) UI.
I can certainly go through and click “trash” on all 200+ comments, but that seems.. excessive. Is there another way to do this that I am missing?
Alternative for people reading this with a fear for SQL…………… (or finding this via Google after Januari 2011):
Wait for this action until 3.1 comes out, then go to a post, check all comments and bulk “move to trash” 🙂 (it should come out any day now) (http://wordpress.org/about/roadmap/)
(or download 3.1 RC3 from http://wordpress.org/download/release-archive/)
Example:
http://edward.de.leau.net/files/bulkremove.png
Hi @Jeff Atwood:
I’m assuming you have MySQL query access. This will give you all comments for your blog post whose URL slug is
'your-blog-post'
(the slug is the last segment in your post’s URL if you are using pretty permalinks, i.e. for http://example.com/2011/01/foo-bar-baz/ your slug would be'foo-bar-baz'
):And this will give you all the comment metadata:
So… run these two commands (but be sure to replace the post_name value to be equal to yours):
P.S. This will of course fully delete them but unless you do want to keep them in the trash this is easier than moving them to the trash.
WordPress doesn’t support bulk management of comments on a post by post basis. Although it does have a comment management section directly at the post’s edit page. As you said, you would have to click on “Trash” on every single comment:
Alternately you could take a back up of the wp_comments and wp_commentmeta table and run the following queries:
Find post ID. Lets say the relevant id is X.
Add relevant comment metadata just to preserve integrity:
Trash all comments:
I do not advise removing directly from the database as data may have dependencies one might end up with orphan records.
With the post ID (add it in
ADDPOSTID
), save the script bellow and add the PHP file in the root of your WordPress website, login as Admin and call the file directly on your browser:Nowadays, the best solution if you can install WP-CLI on the server would be using it this way:
This is not enough, you must also update the column count, otherwise it will not be displayed correctly.
Here is a sample code for a multisite install.