A WordPress-centric search engine for devs and theme authors



get_approved_comments ›

Since2.0.0
Deprecatedn/a
get_approved_comments ( $post_id, $args = array() )
Parameters: (2)
  • (int) $post_id The ID of the post.
    Required: Yes
  • (array) $args Optional. See WP_Comment_Query::query() for information on accepted arguments.
    Required: No
    Default: array()
Returns:
  • (int|array) $comments The approved comments, or number of comments if `$count` argument is true.
Defined at:
Codex:
Change Log:
  • 4.1.0 Refactored to leverage WP_Comment_Query over a direct query.

Retrieve the approved comments for post $post_id.



Source

function get_approved_comments( $post_id, $args = array() ) {
	if ( ! $post_id ) {
		return array();
	}

	$defaults = array(
		'status'  => 1,
		'post_id' => $post_id,
		'order'   => 'ASC',
	);
	$r = wp_parse_args( $args, $defaults );

	$query = new WP_Comment_Query;
	return $query->query( $r );
}