get_approved_comments( int $post_id, array $args = array() )
Retrieves the approved comments for a post.
Parameters
- $post_id
-
(Required) The ID of the post.
- $args
-
(Optional) See WP_Comment_Query::__construct() for information on accepted arguments.<br>
- 'status'
(int) Comment status to limit results by. Defaults to approved comments.<br> - 'post_id'
(int) Limit results to those affiliated with a given post ID.<br> - 'order'
(string) How to order retrieved comments. Default 'ASC'.<br>
Default value: array()
- 'status'
Return
(WP_Comment[]|int[]|int) The approved comments, or number of comments if $count
argument is true.
Source
File: wp-includes/comment.php
function get_approved_comments( $post_id, $args = array() ) {
if ( ! $post_id ) {
return array();
}
$defaults = array(
'status' => 1,
'post_id' => $post_id,
'order' => 'ASC',
);
$r = wp_parse_args( $args, $defaults );
$query = new WP_Comment_Query;
return $query->query( $r );
}
Changelog
Version | Description |
---|---|
4.1.0 | Refactored to leverage WP_Comment_Query over a direct query. |
2.0.0 | Introduced. |