Is it possible to hook into the default Recent Comments widget to enable it to display comments for attachment posts? If so, how?


you can use the widget_comments_args filter to modify the default args of the recent comments widget:

function wpse80087_widget_comments_args( $args )
    $args = array( 'number' => 5, 'post_type' => 'attachment', 'status' => 'approve', 'post_status' => 'inherit' );
    return $args;
add_filter( 'widget_comments_args', 'wpse80087_widget_comments_args', 10, 1 );
  • It displays the widget title only, no comments. – Bosco Jan 10 '13 at 22:05
  • Yes, sorry, post_status should have been inherit, I edited my answer – diggy Jan 10 '13 at 22:13
  • Check that: now it displays only the comments on attachment posts. – Bosco Jan 10 '13 at 22:20
  • Apologies for not being clear: Is it possible for the widget to display all comments, including attachments? 'post_type' => array('attachment', 'page', 'post'), – Bosco Jan 10 '13 at 22:45
  • Works perfect! To merge all comments you limit it to 'status' => 'approve' Thanks! – Bosco Jan 10 '13 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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