Languages: English • 日本語 (Add your language)
Retrieves the value of the total number of comments, Trackbacks, and Pingbacks for a post. Unlike comments_number() this function will return the value as a numeric value.
<?php $my_var = get_comments_number( $post_id ); ?>
To make get_comments_number work like comments_number you can use this code.
$num_comments = get_comments_number(); // get_comments_number returns only a numeric value if ( comments_open() ) { if ( $num_comments == 0 ) { $comments = __('No Comments'); } elseif ( $num_comments > 1 ) { $comments = $num_comments . __(' Comments'); } else { $comments = __('1 Comment'); } $write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>'; } else { $write_comments = __('Comments are off for this post.'); }