Retrieves the approved comments for a post.
$post_idintrequired
$argsarrayoptional
status intpost_id intorder string'ASC'.Default:array()
$count argument is true.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–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_approved_comments