separate_comments

Separates an array of comments into an array keyed by comment_type.

Description

(array) separate_comments( (array) &$comments ); 

Returns (array)

Array of comments keyed by comment_type.

Parameters (1)

0. $comments (array) => &$comments
Array of comments

Usage

  1. if ( !function_exists( 'separate_comments' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Array of comments 
  5. $comments = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = separate_comments($comments); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function separate_comments(&$comments) { 
  2. $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array()); 
  3. $count = count($comments); 
  4. for ( $i = 0; $i < $count; $i++ ) { 
  5. $type = $comments[$i]->comment_type; 
  6. if ( empty($type) ) 
  7. $type = 'comment'; 
  8. $comments_by_type[$type][] = &$comments[$i]; 
  9. if ( 'trackback' == $type || 'pingback' == $type ) 
  10. $comments_by_type['pings'][] = &$comments[$i]; 
  11.  
  12. return $comments_by_type;