# get_comments_number()

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

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

## Сигнатура

```php
get_comments_number( int|WP_Post $post ): string|int
```

## Описание

Получает количество комментариев к записи.

## Параметры

- `$post` `int|WP_Post` — необязательный. ID записи или объект WP_Post. По умолчанию — глобальная переменная $post.

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

`string|int`

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

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

```php
function get_comments_number( $post = 0 ) {
	$post = get_post( $post );

	$comments_number = $post ? $post->comment_count : 0;
	$post_id         = $post ? $post->ID : 0;

	/**
	 * Filters the returned comment count for a post.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $comments_number A string representing the number of comments a post has, otherwise 0.
	 * @param int        $post_id Post ID.
	 */
	return apply_filters( 'get_comments_number', $comments_number, $post_id );
}
```

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

- 1.5.0 — Introduced.

## Связанные

Использует: [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: [`print_embed_comments_button`](https://chugunov.pro/api-wordpress/functions/print_embed_comments_button/), [`get_comments_number_text`](https://chugunov.pro/api-wordpress/functions/get_comments_number_text/), `WP_List_Table::comments_bubble`, [`comments_popup_link`](https://chugunov.pro/api-wordpress/functions/comments_popup_link/), [`get_comments_link`](https://chugunov.pro/api-wordpress/functions/get_comments_link/).

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