WordPress filter hook · part of WordPress core

widget_comments_args

A WordPress core filter that 22 plugins also fire themselves, running on 407K+ sites between them.

“This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php”

How to use widget_comments_args

It's a filter: your callback receives the value, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'widget_comments_args', function( $query_args ) {
	// Change $query_args here.
	return $query_args;
}, 10, 1 );

Argument names come from Video Gallery's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

22 plugins that fire widget_comments_args

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Gutenberg icon Gutenberg400,000+ installs apply_filters( 'widget_comments_args', array( 'number' => $attributes['commentsToShow'], 'status' => 'approve', 'post_status' => 'publish', ), array() ) build/scripts/block-library/latest-comments.php:55
  2. WpStream icon WpStream3,000+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', ), $instance ) hello-wpstream/framework/widgets/class-wpstream-recent-comments-widget.php:65
  3. Video Gallery icon Video Gallery2,000+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  4. xili-language icon xili-language600+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) xili-includes/xili-language-widgets.php:317
  5. Customer Support Ticket System & Helpdesk icon Customer Support Ticket System & Helpdesk400+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  6. Employee Spotlight icon Employee Spotlight300+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  7. Employee Directory icon Employee Directory100+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  8. Recent Comments Widget with Comment Excerpts icon Recent Comments Widget with Comment Excerpts100+ installs apply_filters( 'widget_comments_args', array( 'number' => 150, 'status' => 'approve', 'post_status' => 'publish', ), $instance ) recent_comments_widget_with_excerpts.php:72
  9. Polygon Recent Comments With Avatar icon Polygon Recent Comments With Avatar100+ installs apply_filters( 'widget_comments_args', array('number' => $num_comments, 'status' => 'approve', 'post_status' => 'publish', 'type' => 'comment') ) polygon-recent-comments-with-avatar.php:90
  10. WP Recent Comments With Avatars icon WP Recent Comments With Avatars80+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'type' => 'comment' ) ) wp-recent-comments-with-avatars.php:79
  11. FF Tab Widget icon FF Tab Widget70+ installs apply_filters( 'widget_comments_args', array( 'number' => $commentlimit, 'status' => 'approve', 'post_status' => 'publish' ) ) ff-tab-widget.php:312
  12. Simple Contact Form Plugin for WordPress icon Simple Contact Form Plugin for WordPress40+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  13. Project Management, Bug and Issue Tracking Plugin icon Project Management, Bug and Issue Tracking Plugin20+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  14. Event RSVP and Simple Event Management Plugin icon Event RSVP and Simple Event Management Plugin20+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  15. JS Widgets icon JS Widgets10+ installs apply_filters( 'widget_comments_args', array( 'number' => $instance['number'], 'status' => 'approve', 'post_status' => 'publish', ) ) core-adapter-widgets/recent-comments/class.php:76
  16. Easy Accordion FAQ and Knowledge Base Software for WordPress icon Easy Accordion FAQ and Knowledge Base Software for WordPress10+ installs apply_filters( 'widget_comments_args', $this->query_args ) includes/class-emd-widget.php:355
  17. HTML Classified Recent Posts & Comments Widgets icon HTML Classified Recent Posts & Comments Widgets10+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) html-classified-recent-post-comments-widgets.php:175
  18. Pz-RecentComments icon Pz-RecentComments10+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'type' => 'comment', 'post_status' => 'publish' ) ) pz-recentcomments.php:42
  19. Smart Recent Comments icon Smart Recent Comments10+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) index.php:88
  20. Advance Widget Pack icon Advance Widget Pack10+ installs apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', ) ) includes/class-awp-recent-comments.php:27
  21. Poly Comments icon Poly CommentsFewer than 10 installs apply_filters( 'widget_comments_args', array('number' => $num_comments, 'status' => 'approve', 'post_status' => 'publish', 'type' => 'comment') ) includes/widgets.php:53
  22. Fox009 Recent Comments Widget icon Fox009 Recent Comments WidgetFewer than 10 installs apply_filters( 'widget_comments_args', array( 'post_type' => '', 'number' => $comment_params['number'], 'offset' => $comment_params['offset'], 'orderby' => $comment_params['orderby'], 'order' => $comment_params['order'], 'status' => $comment_params['status'], 'type' => $comment_params['type'] ) ) includes/widget.php:14

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.