Summery Summery
Retrieves the amount of comments a post has.
Syntax Syntax
Parameters Parameters
- $post_id
-
(Optional) Post ID or WP_Post object. Default is the global
$post
.
Return Return
(string|int) If the post exists, a numeric string representing the number of comments the post has, otherwise 0.
Source Source
File: wp-includes/comment-template.php
* @since 1.5.0 * * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. * @return string|int If the post exists, a numeric string representing the number of comments * the post has, otherwise 0. */ function get_comments_number( $post_id = 0 ) { $post = get_post( $post_id ); if ( ! $post ) { $count = 0; } else { $count = $post->comment_count; $post_id = $post->ID; } /** * Filters the returned comment count for a post. * * @since 1.5.0
Advertisement
Changelog Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |