Title: WP_Comment::get_children
Published: December 9, 2015
Last modified: August 20, 2026

---

# WP_Comment::get_children( array $args = array() ): 󠀁[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)󠁿[]|int[]|int

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#wp--skip-link--target)

Gets the children of a comment.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#parameters)󠁿

 `$args`arrayoptional

Array of arguments used to pass to [get_comments()](https://developer.wordpress.org/reference/functions/get_comments/)
and determine format.
 Any other argument accepted by [WP_Comment_Query::__construct()](https://developer.wordpress.org/reference/classes/WP_Comment_Query/__construct/)
may also be passed, and is forwarded to `get_comments()`. Note that `parent` is 
always overridden with this comment’s ID. A `$count` or `$fields` query returns 
the direct children only, and does not populate the comment’s cached children, since
that cache holds `WP_Comment` objects.

 * `format` string
 * Return value format. `'tree'` for a hierarchical tree, `'flat'` for a flattened
   array.
    Default `'tree'`.
 * `status` string
 * Comment status to limit results by. Accepts `'hold'` (`comment_status=0`), `'
   approve'` (`comment_status=1`), `'all'`, or a custom comment status.
    Default`'
   all'`.
 * `hierarchical` string
 * Whether to include comment descendants in the results.
    `'threaded'` returns 
   a tree, with each comment’s children stored in a `children` property on the `
   WP_Comment` object. `'flat'` returns a flat array of found comments plus their
   children. Pass `false` to leave out descendants. The parameter is ignored (forced
   to `false`) when `$fields` is `'ids'` or `'counts'`. Accepts `'threaded'`, `'
   flat'`, or false. Default: `'threaded'`.
 * `orderby` string|array
 * Comment 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 disable `ORDER BY` clause.
 * `fields` string
 * Which fields to return. Accepts `'ids'` for comment IDs, or an empty string for
   full `WP_Comment` objects.
 * `count` bool
 * Whether to return a comment count rather than comments.
    Default false.
 * `type` string
 * Limit results to comments of a given type, such as `'comment'`, `'pingback'`,`'
   trackback'`, or `'note'`. Accepts `'all'` for every type.
 * `number` int
 * Maximum number of comments to retrieve. Default empty (no limit).
 * `post_id` int
 * Limit results to comments on a given post. Default 0.
 * `order` string
 * How to order retrieved comments. Accepts `'ASC'` or `'DESC'`.
    Default `'DESC'`.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#return)󠁿

 [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)[]|int[]
|int Array of `WP_Comment` objects, an array of comment IDs when `$fields` is `'
ids'`, or the number of children when `$count` is true.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#source)󠁿

    ```php
    public function get_children( $args = array() ) {
    	$defaults = array(
    		'format'       => 'tree',
    		'status'       => 'all',
    		'hierarchical' => 'threaded',
    		'orderby'      => '',
    	);

    	/** @var array{ format: 'tree'|'flat', status: string, hierarchical: 'threaded'|'flat'|false, orderby: string|string[]|false, fields?: 'ids'|'', count?: bool, type?: string, number?: int, post_id?: int, order?: 'ASC'|'DESC', ... } $_args */
    	$_args           = wp_parse_args( $args, $defaults );
    	$_args['parent'] = $this->comment_ID;

    	/*
    	 * A 'count' or 'ids' query returns an integer or a list of comment IDs rather than
    	 * WP_Comment objects. Neither may be written to the children cache, which holds
    	 * WP_Comment objects and is read back by add_child(), get_child(), and the 'flat'
    	 * format below. Return the result directly and leave the cache untouched. The two
    	 * branches must stay separate: each is narrowed independently, and `count` is only
    	 * safe to overwrite in the 'ids' branch.
    	 */
    	if ( ! empty( $_args['count'] ) ) {
    		return get_comments( $_args );
    	} elseif ( isset( $_args['fields'] ) && 'ids' === $_args['fields'] ) {
    		$_args['count'] = false; // For static analysis of the conditional return type.
    		return get_comments( $_args );
    	}

    	// Only WP_Comment objects are returned past this point. Stated positively for static analysis.
    	$_args['count']  = false;
    	$_args['fields'] = '';

    	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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-comment.php#L385)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-comment.php#L385-L439)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#related)󠁿

| Uses | Description | 
| [get_comments()](https://developer.wordpress.org/reference/functions/get_comments/)`wp-includes/comment.php` |

Retrieves a list of comments.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_Comment/get_children/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | A `count` or `fields` query now returns its result directly rather than erroneously storing it in the comment’s children cache. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_comment%2Fget_children%2F)
before being able to contribute a note or feedback.