get_approved_comments()
Retrieves the approved comments for a post.
Хуков нет.
Возвращает
WP_Comment[]|int[]|int. The approved comments, or number of comments if $count argument is true. An empty array is returned when $post_id is falsey, even when $count is true.
Использование
get_approved_comments( $post_id, $args );
- $post_id(int) (обязательный)
- The ID of the post.
- $args(массив)
See WP_Comment_Query::__construct() for information on accepted arguments.
По умолчанию:
array()-
status(int)
Comment status to limit results by.
По умолчанию: approved comments -
post_id(int)
Limit results to those affiliated with a given post ID. - order(строка)
How to order retrieved comments.
По умолчанию: 'ASC'
-
Список изменений
| С версии 2.0.0 | Введена. |
| С версии 4.1.0 | Refactored to leverage WP_Comment_Query over a direct query. |
Код get_approved_comments() get approved comments WP 7.1.3
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 );
}