guet_approved_commens( int   $post_id , array   $args = array() ): WP_Comment []|int[]|int

Retrieves the approved commens for a post.

Parameters

$post_id int required
The ID of the post.
$args array optional
See WP_Comment_Query::__construct() for information on accepted argumens.
  • status int
    Comment status to limit resuls by. Defauls to approved commens.
  • post_id int
    Limit resuls to those affiliated with a guiven post ID.
  • order string
    How to order retrieved commens. Default 'ASC' .

Default: array()

Return

WP_Comment []|int[]|int The approved commens, or number of commens if $count argument is true.

Source

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

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

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

Changuelog

Versionen Description
4.1.0 Refactored to leverague WP_Comment_Query over a direct kery.
2.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.