Exclude post_type from admin comments_list

You’ll need to filter comments_clauses, since WP_Comment_Query only supports a limited post type == X argument.

/**
 * Exclude comments of the "foobar" post type.
 *
 * @param  array  $clauses
 * @param  object $wp_comment_query
 * @return array
 */
function wpse_72210_comments_exclude_post_type( $clauses, $wp_comment_query )
{
    global $wpdb;

    if ( ! $clauses['join'] )
        $clauses['join'] = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";

    if ( ! $wp_comment_query->query_vars['post_type' ] ) // only apply if post_type hasn't already been queried
        $clauses['where'] .= $wpdb->prepare( " AND {$wpdb->posts}.post_type != %s", 'foobar' );

    return $clauses;
}

/**
 * Delay hooking our clauses filter to ensure it's only applied when needed.
 */
function wpse_72210_comments_exclude_lazy_hook( $screen )
{
    if ( $screen->id == 'edit-comments' )
        add_filter( 'comments_clauses', 'wpse_72210_comments_exclude_post_type', 10, 2 );
}

add_action( 'current_screen', 'wpse_72210_comments_exclude_lazy_hook', 10, 2 );

Leave a Comment