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.
定義位置
相關方法
get_commentshave_commentsget_pending_comments_numget_page_of_commentget_comment
引入
2.0.0
棄用
-

get_approved_comments: 這個函式返回一個已批准的評論陣列。

檢索一個文章的批准評論。

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

常見問題

FAQs
檢視更多 >