wp_count_comments()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_count_comments( int $post_id ): stdClass
Описание
Статистика комментариев кэшируется, а затем извлекается, если она уже есть в кэше.
См. alsoget_comment_count(): обрабатывает получение актуального количества комментариев.
Оригинал (английский)
The comment stats are cached and then retrieved, if they already exist in the cache.
- get_comment_count(): Which handles fetching the live comment counts.
Параметры
$post_id
int
необязательный
Возвращаемое значение
stdClass
Исходный код
wp-includes/comment.php:1460
function wp_count_comments( $post_id = 0 ) {
$post_id = (int) $post_id;
/**
* Filters the comments count for a given post or the whole site.
*
* @since 2.7.0
*
* @param array|stdClass $count An empty array or an object containing comment counts.
* @param int $post_id The post ID. Can be 0 to represent the whole site.
*/
$filtered = apply_filters( 'wp_count_comments', array(), $post_id );
if ( ! empty( $filtered ) ) {
return $filtered;
}
$count = wp_cache_get( "comments-{$post_id}", 'counts' );
if ( false !== $count ) {
return $count;
}
$stats = get_comment_count( $post_id );
$stats['moderated'] = $stats['awaiting_moderation'];
unset( $stats['awaiting_moderation'] );
$stats_object = (object) $stats;
wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' );
return $stats_object;
}
История изменений
| Версия | Описание |
|---|---|
| 2.5.0 | Introduced. |

