On this page
get_comments_number( int|WP_Post $post ): string|int
Retrieves the amount of comments a post has.
Parameters
Return
string|int If the post exists, a numeric string representing the number of comments the post has, otherwise 0.
Source
File: wp-includes/comment-template.php. View all references
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 );
}
Hooks
- apply_filters( 'get_comments_number',
string|int $count ,int $post_id ) -
Filters the returned comment count for a post.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| print_embed_comments_button() wp-includes/embed.php | Prints the necessary markup for the embed comments button. |
| get_comments_number_text() wp-includes/comment-template.php | Displays the language string for the number of comments the current post has. |
| WP_List_Table::comments_bubble() wp-admin/includes/class-wp-list-table.php | Displays a comment count bubble. |
| comments_popup_link() wp-includes/comment-template.php | Displays the link to the comments for the current post ID. |
| get_comments_link() wp-includes/comment-template.php | Retrieves the link to the current post comments. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_comments_number