I'm working on a site that has 150,000 comments with an obvious hit in performance; is there an SQL query that can delete all comments older than say 90 days? They're not spam comments, and they are all approved; they're just too numerous.

And: what about bulk changing all posts older than 90 days to untick "Allow comments" and "Allow trackbacks and pingbacks"? So they don't get re-commented?

  • The Discussion Settings contains an option Automatically close comments on articles older than X days, I think that covers the second case. Is it possible to render the remaining old comments once to static HTML snippets and include them, instead of doing database queries? That way you still can view the old information, just not add to it.
    – Jan Fabry
    Commented Apr 26, 2011 at 7:19

1 Answer 1


Regarding comments- what about the case where a comment older than 90 days has child replies younger than 90 days?

for comment and pingback status, this should do it:

UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE post_date < DATE_SUB(NOW(), INTERVAL 3 MONTH) AND post_status = 'publish';

  • Good point about the parent-child comments, although they might still work: if you move a parent comment to the trash, the child comments are still displayed.
    – Jan Fabry
    Commented Apr 26, 2011 at 7:23
  • and @Jan: Yes, I need to delete child comments, too. Commented Jun 20, 2011 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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