Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

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:

share|improve this answer
add comment

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'):

SELECT * from wp_comments WHERE comment_post_ID IN (
  SELECT ID FROM wp_posts WHERE post_name='your-post-slug'
)

And this will give you all the comment metadata:

SELECT * from wp_commentmeta WHERE comment_id IN (
  SELECT comment_ID from wp_comments WHERE comment_post_ID IN (
    SELECT ID FROM wp_posts WHERE post_name='your-post-slug'
  )
) 

So... run these two commands (but be sure to replace the post_name value to be equal to yours):

DELETE from wp_commentmeta WHERE comment_id IN (
  SELECT comment_ID from wp_comments WHERE comment_post_ID IN (
    SELECT ID FROM wp_posts WHERE post_name='your-post-slug'
  )
);

DELETE from wp_comments WHERE comment_post_ID IN (
  SELECT ID FROM wp_posts WHERE post_name='your-post-slug'
);

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.

share|improve this answer
add comment

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:

alt text

Alternately you could take a back up of the wp_comments and wp_commentmeta table and run the following queries:

  1. Find post ID. Lets say the relevant id is X.

    SELECT ID from wp_posts WHERE post_title='Hello world!'; 
    
  2. Add relevant comment metadata just to preserve integrity:

    INSERT INTO wp_commentmeta (comment_id, meta_key, meta_value) SELECT comment_ID, "wp_trash_meta_time", UNIX_TIMESTAMP() FROM wp_comments WHERE comment_post_ID=@x;
    
    INSERT INTO wp_commentmeta (comment_id, meta_key, meta_value) SELECT comment_ID, "wp_trash_meta_status",comment_approved FROM wp_comments WHERE comment_post_ID=@x;
    
  3. Trash all comments:

    UPDATE wp_comments SET comment_approved='trash' WHERE comment_post_ID=@x;
    
share|improve this answer
    
excellent answer -- out of curiosity how traumatic is it if the comment metadata isn't inserted? What breaks, if anything? –  Jeff Atwood Jan 22 '11 at 9:06
    
I've not been able to find a big differene except that the trashed comments won't be deleted after the EMPTY_TRASH_DAYS days. (wp-includes/default-constants.php). If you untrash them their approval status will default to "unapproved". –  rsman Jan 22 '11 at 14:00
1  
I assume you should execute step 3 before step 2 if you really want to keep the old approval status? Now they would be set to trash in step 2, and then we copy this trash status in step 3, not the previous status. –  Jan Fabry Jan 24 '11 at 16:17
    
@Jan Thanks for pointing it out, edited accordingly. –  rsman Jan 24 '11 at 16:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.