1

I use comments with a custom comment type in my plugin to notify users of various events created by the plugin.

The problem is I don't want these cluttering up the standard comments so I need to filter out those custom comments from the manage comments screen as well as the recent comments dashboard widget.

Does anyone have any ideas on how to do this?

2
  • How is your plugin making these 'custom comment type'. I do not know of any native WordPress way for custom comments.
    – Evan Yeung
    Commented Jan 22, 2012 at 21:50
  • By using wp_inset_comment($args). One of the fields in wp_comments is comment_type which can be either '' for normal comments, or ping/track, or whatever you like codex.wordpress.org/Function_Reference/wp_insert_comment Commented Jan 22, 2012 at 21:53

1 Answer 1

3

Doh, looks like the answer was staring me in the face.

add_filter( 'comments_clauses', 'myPlugin_exclude_custom_comments', 10, 1);
function myPlugin_exclude_custom_comments( $clauses ) {

    // Hide all those comments which aren't of type system_message
    $clauses['where'] .= ' AND comment_type != "system_message"';   

    return $clauses;
}

What this does is edit all comment queries to find comments that don't have a type of system_message

Hope this helps someone :)

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.