Title: separate_comments
Published: April 25, 2014
Last modified: February 24, 2026

---

# separate_comments( WP_Comment[] $comments ): array<string,

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#wp--skip-link--target)

Separates an array of comments into an array keyed by comment_type.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#parameters)󠁿

 `$comments`[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)[]
required

Array of comments.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#return)󠁿

 array<string, [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)[]
> Array of comments keyed by comment type.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#source)󠁿

    ```php
    function separate_comments( &$comments ) {
    	$comments_by_type = array(
    		'comment'   => array(),
    		'trackback' => array(),
    		'pingback'  => array(),
    		'pings'     => array(),
    	);

    	$count = count( $comments );

    	for ( $i = 0; $i < $count; $i++ ) {
    		$type = $comments[ $i ]->comment_type;

    		if ( empty( $type ) ) {
    			$type = 'comment';
    		}

    		$comments_by_type[ $type ][] = &$comments[ $i ];

    		if ( 'trackback' === $type || 'pingback' === $type ) {
    			$comments_by_type['pings'][] = &$comments[ $i ];
    		}
    	}

    	return $comments_by_type;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L938)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L938-L963)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_list_comments()](https://developer.wordpress.org/reference/functions/wp_list_comments/)`wp-includes/comment-template.php` |

Displays a list of comments.

  | 
| [comments_template()](https://developer.wordpress.org/reference/functions/comments_template/)`wp-includes/comment-template.php` |

Loads the comment template specified in $file.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/separate_comments/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fseparate_comments%2F)
before being able to contribute a note or feedback.