Definition:
function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) {}
Parameters
- string $status: Comment status (approved, spam, trash, etc)
- string $s: Term to search for
- int $start: Offset to start at for pagination
- int $num: Maximum number of comments to return
- int $post: Post ID or 0 to return all comments
- string $type: Comment type (comment, trackback, pingback, etc)
Return values
returns:[0] contains the comments and [1] contains the total number of comments that match (ignoring $start and $num)
Source code
function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) { global $wpdb; $start = abs( (int) $start ); $num = (int) $num; $post = (int) $post; $count = wp_count_comments(); $index = ''; if ( 'moderated' == $status ) { $approved = "c.comment_approved = '0'"; $total = $count->moderated; } elseif ( 'approved' == $status ) { $approved = "c.comment_approved = '1'"; $total = $count->approved; } elseif ( 'spam' == $status ) { $approved = "c.comment_approved = 'spam'"; $total = $count->spam; } elseif ( 'trash' == $status ) { $approved = "c.comment_approved = 'trash'"; $total = $count->trash; } else { $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )"; $total = $count->moderated + $count->approved; $index = 'USE INDEX (c.comment_date_gmt)'; } if ( $post ) { $total = ''; $post = " AND c.comment_post_ID = '$post'"; } else { $post = ''; } $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT $start, $num"; if ( 'comment' == $type ) $typesql = "AND c.comment_type = ''"; elseif ( 'pings' == $type ) $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )"; elseif ( 'all' == $type ) $typesql = ''; elseif ( !empty($type) ) $typesql = $wpdb->prepare("AND c.comment_type = %s", $type); else $typesql = ''; if ( !empty($type) ) $total = ''; $query = "FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' "; if ( $s ) { $total = ''; $s = $wpdb->escape($s); $query .= "AND (c.comment_author LIKE '%$s%' OR c.comment_author_email LIKE '%$s%' OR c.comment_author_url LIKE ('%$s%') OR c.comment_author_IP LIKE ('%$s%') OR c.comment_content LIKE ('%$s%') ) AND $approved $typesql"; } else { $query .= "AND $approved $post $typesql"; } $comments = $wpdb->get_results("SELECT * $query $orderby"); if ( '' === $total ) $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) $query"); update_comment_cache($comments); return array($comments, $total); }
4393
No comments yet... Be the first to leave a reply!