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 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?

share|improve this question
    
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 Apr 26 '11 at 7:19

1 Answer 1

up vote 1 down vote accepted

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';

share|improve this answer
    
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 Apr 26 '11 at 7:23
    
and @Jan: Yes, I need to delete child comments, too. –  songdogtech Jun 20 '11 at 16:56

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.