wppaste
WordPress

WP_Comment::get_children( array $args = array() ): WP_Comment[]

Since
4.4.0
Source
wp-includes/class-wp-comment.php:268
Gets the children of a comment.

Compatibility

WordPress
since 4.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarrayoptional
Array of arguments used to pass to get_comments() and determine format.Default: array()
  • $formatstringdefault: 'tree'

    Return value format. 'tree' for a hierarchical tree, 'flat' for a flattened array.
  • $statusstringdefault: 'all'

    Comment status to limit results by. Accepts 'hold' (comment_status=0), 'approve' (comment_status=1), 'all', or a custom comment status.
  • $hierarchicalstringdefault: 'threaded'

    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.
  • $orderbystring|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.

Return value

WP_Comment[]
Array of WP_Comment objects.

Performance profile

How much work a call to WP_Comment::get_children() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_comments().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
18–29

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_comments()called directly

Further down the call graph this can also reach hook. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Comment::get_children() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always18–27wp_parse_args()
always25–29wp_parse_args(), get_comments()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 49 instructions, 18–29 executed per call, 5 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 2

Source code

	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

Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from WP_Comment[] to WP_Comment[]|int[]|int.verified against source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.