separate_comments( WP_Comment[] $comments ): WP_Comment[]
- Since
- 2.7.0
- Source
wp-includes/comment.php:932
Separates an array of comments into an array keyed by comment_type.
Parameters
$commentsWP_Comment[]- Array of comments
Return
WP_Comment[]- Array of comments keyed by comment_type.
Used by · 2
- comments_template()Loads the comment template specified in $file.
- wp_list_comments()Displays a list of comments.
Source
function separate_comments( &$comments ) { $comments_by_type = array( 'comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array(), ); $count = count( $comments ); for ( $i = 0; $i < $count; $i++ ) { $type = $comments[ $i ]->comment_type; if ( empty( $type ) ) { $type = 'comment'; } $comments_by_type[ $type ][] = &$comments[ $i ]; if ( 'trackback' === $type || 'pingback' === $type ) { $comments_by_type['pings'][] = &$comments[ $i ]; } } return $comments_by_type;}History
Introduced in 2.7.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Return type changed from
WP_Comment[] to array<string,.verified against source2.7.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/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.