Is there a way to get comments with more than one status using get_comments function?

Let's say I would like to get both trash and hold comments.

It is possible to do the same with posts:

get_posts(array('post_status' => 'draft,private,trash'));
get_posts(array('post_status' => array('draft', 'private', 'trash')));

What I want to do is:

get_comments(array('status' => 'hold,trash'));
get_comments(array('status' => array('hold', 'trash')));

As of the Wordpress codex there is no such option. But you could just combine two or more comment arrays using plain PHP:

    get_comments( array( 'status' => 'hold' ) ),
    get_comments( array( 'status' => 'trash' ) )



| improve this answer | |
  • 1
    Make sure both parts are actually arrays. The function can return NULL in some cases, array_merge() will trigger an error then. – fuxia Dec 27 '12 at 17:42
  • Yeah, I know PHP quite well :) – akashivskyy Dec 27 '12 at 17:54
  • Works nicely for approved and unapproved comments. The merge even supports correct threading for unapproved comments. – Radek Oct 15 '13 at 22:20

Not possible. You have to filter comments_clauses:

add_filter( 'comments_clauses', 'wpse_77415_comment_clauses_filter' );

function wpse_77415_comment_clauses_filter( $clauses )
    $clauses['where'] .= " ( comment_approved = 'hold' OR comment_approved = 'trash' )";
    // maybe remove the original 'comment_approved' statement …

    return $clauses;

More examples:

| improve this answer | |
  • Seems you know WordPress better than @feeela, but his method is more simple and more convenient. Thanks, for the code, anyway, maybe I will use it in the future. +1 – akashivskyy Dec 27 '12 at 17:33
  • "Not possible." Well, you provided a solution that made it possible… – feeela Dec 27 '12 at 19:05
  • It's not possible do do it just like that, you need to filter the sql clause. – akashivskyy Dec 27 '12 at 20:34

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.