# separate_comments()

URL: https://chugunov.pro/api-wordpress/functions/separate_comments/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.7.0.

## Сигнатура

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

## Описание

Разделяет массив комментариев на массив с ключами по comment_type.

## Параметры

- `$comments` `WP_Comment[]` — обязательный. Массив комментариев.

## Возвращаемое значение

`array<string,` — WP_Comment

## Исходный код

Файл: `wp-includes/comment.php:941`

```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;
}
```

## История изменений

- 2.7.0 — Introduced.

## Связанные

Используется в: [`wp_list_comments`](https://chugunov.pro/api-wordpress/functions/wp_list_comments/), [`comments_template`](https://chugunov.pro/api-wordpress/functions/comments_template/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/separate_comments/
