#37: comments_per_page

The comments_per_page filter allows you to define the number of comments to list per page in the comments list table.

It is evaluated in:

comments_per_page accepts 2 arguments:

  1. int $comments_per_page The number of comments to list per page.
  2. string $comment_status The comment status name. Default is ‘all’.

Example:

I don’t know about you, but when I go to clean out spam comments, it’s irritating to have that extra step of upping the comments per page — the default is 20 — just so I can bulk-delete them faster. The following example raises the comments-per-page amount only when you’re in the ‘Spam’ filtered view.

<?php
/**
* Increase comments-per-page limit when viewing spam comments
*
* @see WP_Comments_List_Table::get_per_page(), WP_Screen::render_per_page_options()
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The current comment status view. Default is 'all'.
*
* @return int The filtered number of comments to list per page.
*/
function wpdocs_delete_more_spam_comments( $comments_per_page, $comment_status ) {
if ( 'spam' == $comment_status )
$comments_per_page = 50;
return $comments_per_page;
}
add_filter( 'comments_per_page', 'wpdocs_delete_more_spam_comments', 10, 2 );

View the code example on Gist.

Have a suggested improvement? You can fork the Gist and comment back with the link. If all is agreeable, I’ll merge in your changes. Crowd-sourced documentation FTW!

Leave a Reply

Your email address will not be published. Required fields are marked *