Uses
| Uses | Description |
|---|---|
| wp-includes/class-wp-comment-query.php: WP_Comment_Query::__construct() | Constructor. |
| wp-includes/functions.php: wp_parse_args() | Merge user defined arguments into defaults array. |
Retrieve the approved comments for post $post_id.
(int) (Required) The ID of the post.
(array) (Optional) See WP_Comment_Query::__construct() for information on accepted arguments.
Default value: array()
(int|array) The approved comments, or number of comments if $count argument is true.
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',
);
$parsed_args = wp_parse_args( $args, $defaults );
$query = new WP_Comment_Query;
return $query->query( $parsed_args );
} | Version | Description |
|---|---|
| 4.1.0 | Refactored to leverage WP_Comment_Query over a direct query. |
| 2.0.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_approved_comments