函数原型
get_comments_number( int|WP_Post $post ): string|int
函数描述
Retrieves the amount of comments a post has.
是否弃用
未弃用
函数参数
-
$post
int|WP_Post
Optional - Post ID or WP_Post object. Default is the global
$post.
函数返回值
string|int If the post exists, a numeric string representing the number of comments the post has, otherwise 0.
函数位置
File: wp-includes/comment-template.php.
函数源码
function get_comments_number( $post = 0 ) {
$post = get_post( $post );
$count = $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 $count A string representing the number of comments a post has, otherwise 0.
* @param int $post_id Post ID.
*/
return apply_filters( 'get_comments_number', $count, $post_id );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |

