Our wp_comments has millions of rows.

When we load /wp/wp-admin/edit-comments.php it would timeout.

Looking at mysql, this simple query is taking a long time

SELECT  wp_comments.comment_ID FROM wp_comments  
WHERE ( ( comment_approved = '0' OR comment_approved = '1' ) ) 
AND comment_type IN ('pingback', 'trackback')
ORDER BY wp_comments.comment_date_gmt

Is there away to edit the edit-comments.php comment dashboard to work only on comments for the last year instead of every commens in the table?

1 Answer 1


Was able to fix it by putting this in functions.php

// fix query timeout in wp-admin/edit-comment.php page
add_action('pre_get_comments', 'pre_get_comments_any_status');
function pre_get_comments_any_status($comment_query) {
  if (empty($comment_query->query_vars['status'])) {
    $comment_query->query_vars['status'] = 'any';

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.