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: 这个函数返回一个已批准的评论数组。

检索一个文章的批准评论。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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
查看更多 >