WP_Comment::get_children( array $args = array() ): WP_Comment[]
Get the children of a comment.
Parameters
-
$args
array Optional -
Array of arguments used to pass to get_comments() and determine format.
format
stringReturn value format.'tree'
for a hierarchical tree,'flat'
for a flattened array.
Default'tree'
.status
stringComment status to limit results by. Accepts'hold'
(comment_status=0
),'approve'
(comment_status=1
),'all'
, or a custom comment status.
Default'all'
.hierarchical
stringWhether to include comment descendants in the results.
'threaded'
returns a tree, with each comment's children stored in achildren
property on theWP_Comment
object.
'flat'
returns a flat array of found comments plus their children.
Passfalse
to leave out descendants.
The parameter is ignored (forced tofalse
) when$fields
is'ids'
or'counts'
.
Accepts'threaded'
,'flat'
, or false. Default:'threaded'
.orderby
string|arrayComment status or array of statuses. To use'meta_value'
or'meta_value_num'
,$meta_key
must also be defined.
To sort by a specific$meta_query
clause, use that clause's array key. Accepts'comment_agent'
,'comment_approved'
,'comment_author'
,'comment_author_email'
,'comment_author_IP'
,'comment_author_url'
,'comment_content'
,'comment_date'
,'comment_date_gmt'
,'comment_ID'
,'comment_karma'
,'comment_parent'
,'comment_post_ID'
,'comment_type'
,'user_id'
,'comment__in'
,'meta_value'
,'meta_value_num'
, the value of $meta_key, and the array keys of$meta_query
. Also accepts false, an empty array, or'none'
to disableORDER BY
clause.
More Arguments from get_comments( ... $args )
Array or query string of comment query parameters.
author_email
stringComment author email address.author_url
stringComment author URL.author__in
int[]Array of author IDs to include comments for.author__not_in
int[]Array of author IDs to exclude comments for.comment__in
int[]Array of comment IDs to include.comment__not_in
int[]Array of comment IDs to exclude.count
boolWhether to return a comment count (true) or array of comment objects (false). Default false.date_query
arrayDate query clauses to limit comments by. See WP_Date_Query.
Default null.fields
stringComment fields to return. Accepts'ids'
for comment IDs only or empty for all fields.include_unapproved
arrayArray of IDs or email addresses of users whose unapproved comments will be returned by the query regardless of$status
.karma
intKarma score to retrieve matching comments for.
meta_key
string|string[]Meta key or keys to filter by.meta_value
string|string[]Meta value or values to filter by.meta_compare
stringMySQL operator used for comparing the meta value.
See WP_Meta_Query::__construct() for accepted values and default value.meta_compare_key
stringMySQL operator used for comparing the meta key.
See WP_Meta_Query::__construct() for accepted values and default value.meta_type
stringMySQL data type that the meta_value column will be CAST to for comparisons.
See WP_Meta_Query::__construct() for accepted values and default value.meta_type_key
stringMySQL data type that the meta_key column will be CAST to for comparisons.
See WP_Meta_Query::__construct() for accepted values and default value.meta_query
arrayAn associative array of WP_Meta_Query arguments.
See WP_Meta_Query::__construct() for accepted values.number
intMaximum number of comments to retrieve.
Default empty (no limit).paged
intWhen used with$number
, defines the page of results to return.
When used with$offset
,$offset
takes precedence. Default 1.offset
intNumber of comments to offset the query. Used to build LIMIT clause. Default 0.no_found_rows
boolWhether to disable theSQL_CALC_FOUND_ROWS
query.
Default: true.orderby
string|arrayComment status or array of statuses. To use'meta_value'
or'meta_value_num'
,$meta_key
must also be defined.
To sort by a specific$meta_query
clause, use that clause's array key. Accepts:
'comment_agent'
'comment_approved'
'comment_author'
'comment_author_email'
'comment_author_IP'
'comment_author_url'
'comment_content'
'comment_date'
'comment_date_gmt'
'comment_ID'
'comment_karma'
'comment_parent'
'comment_post_ID'
'comment_type'
'user_id'
'comment__in'
'meta_value'
'meta_value_num'
- The value of
$meta_key
- The array keys of
$meta_query
- false, an empty array, or
'none'
to disableORDER BY
clause.
'comment_date_gmt'
.order
stringHow to order retrieved comments. Accepts'ASC'
,'DESC'
.
Default:'DESC'
.parent
intParent ID of comment to retrieve children of.
parent__in
int[]Array of parent IDs of comments to retrieve children for.
parent__not_in
int[]Array of parent IDs of comments *not* to retrieve children for.post_author__in
int[]Array of author IDs to retrieve comments for.
post_author__not_in
int[]Array of author IDs *not* to retrieve comments for.
post_id
intLimit results to those affiliated with a given post ID.
Default 0.post__in
int[]Array of post IDs to include affiliated comments for.
post__not_in
int[]Array of post IDs to exclude affiliated comments for.
post_author
intPost author ID to limit results by.post_status
string|string[]Post status or array of post statuses to retrieve affiliated comments for. Pass'any'
to match any value.
post_type
string|string[]Post type or array of post types to retrieve affiliated comments for. Pass'any'
to match any value.post_name
stringPost name to retrieve affiliated comments for.
post_parent
intPost parent ID to retrieve affiliated comments for.
search
stringSearch term(s) to retrieve matching comments for.
status
string|arrayComment statuses to limit results by. Accepts an array or space/comma-separated list of'hold'
(comment_status=0
),'approve'
(comment_status=1
),'all'
, or a custom comment status. Default'all'
.type
string|string[]Include comments of a given type, or array of types.
Accepts'comment'
,'pings'
(includes'pingback'
and'trackback'
), or any custom type string.type__in
string[]Include comments from a given array of comment types.
type__not_in
string[]Exclude comments from a given array of comment types.
user_id
intInclude comments for a specific user ID.hierarchical
bool|stringWhether to include comment descendants in the results.
'threaded'
returns a tree, with each comment's children stored in achildren
property on theWP_Comment
object.'flat'
returns a flat array of found comments plus their children.- Boolean
false
leaves out descendants.
false
) when$fields
is'ids'
or'counts'
. Accepts'threaded'
,'flat'
, or false. Default: false.cache_domain
stringUnique cache key to be produced when this query is stored in an object cache. Default is'core'
.update_comment_meta_cache
boolWhether to prime the metadata cache for found comments.
Default true.update_comment_post_cache
boolWhether to prime the cache for comment posts.
Default false.
Default:
array()
Return
WP_Comment[] Array of WP_Comment
objects.
Source
File: wp-includes/class-wp-comment.php
.
View all references
public function get_children( $args = array() ) {
$defaults = array(
'format' => 'tree',
'status' => 'all',
'hierarchical' => 'threaded',
'orderby' => '',
);
$_args = wp_parse_args( $args, $defaults );
$_args['parent'] = $this->comment_ID;
if ( is_null( $this->children ) ) {
if ( $this->populated_children ) {
$this->children = array();
} else {
$this->children = get_comments( $_args );
}
}
if ( 'flat' === $_args['format'] ) {
$children = array();
foreach ( $this->children as $child ) {
$child_args = $_args;
$child_args['format'] = 'flat';
// get_children() resets this value automatically.
unset( $child_args['parent'] );
$children = array_merge( $children, array( $child ), $child->get_children( $child_args ) );
}
} else {
$children = $this->children;
}
return $children;
}
Changelog
Version | Description |
---|---|
4.4.0 | Introduced. |