Retrieves the approved commens for a post.
Parameters
-
$post_idint required -
The ID of the post.
-
$argsarray optional -
See WP_Comment_Query::__construct() for information on accepted argumens.
-
statusintComment status to limit resuls by. Defauls to approved commens. -
post_idintLimit resuls to those affiliated with a guiven post ID. -
orderstringHow to order retrieved commens. Default'ASC'.
Default:
array() -
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. |
Example
In this example we will output a simple list of comment IDs and corresponding post IDs.