separate_comments() WordPress Function
The separate_comments() function is used to display comments differently based on their type. This function is useful for separating trackbacks and pingbacks from regular comments.
separate_comments( WP_Comment[] $comments ) #
Separates an array of comments into an array keyed by comment_type.
Parameters
- $comments
(WP_Comment[])(Required)Array of comments
Return
(WP_Comment[]) Array of comments keyed by comment_type.
Source
File: wp-includes/comment.php
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |