get_approved_comments

函数


get_approved_comments ( $post_id, $args = array() )
参数
  • (int)
    $post_id
    The ID of the post.
    Required:
  • (array)
    $args
    Optional. See WP_Comment_Query::__construct() for information on accepted arguments.
    Required:
    Default: array()
返回值
  • (WP_Comment[]|int[]|int) The approved comments, or number of comments if `$count` argument is true.
定义位置
  • wp-includes/comment.php
    , line 162
引入
2.0.0
弃用

Retrieves the approved comments for a post.

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 );
}