From 665b15790d191b49d7ab3a2a76bc751ecdfa0a8f Mon Sep 17 00:00:00 2001 From: scribu Date: Wed, 27 Oct 2010 19:05:39 +0000 Subject: [PATCH] Make comment clauses more similar to post clauses. See #15019 git-svn-id: https://develop.svn.wordpress.org/trunk@16020 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 315247e744..43d9b7755c 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -292,14 +292,20 @@ class WP_Comment_Query extends WP_Object_Query { if ( !empty($number) ) { if ( $offset ) - $limit = 'LIMIT ' . $offset . ',' . $number; + $limits = 'LIMIT ' . $offset . ',' . $number; else - $limit = 'LIMIT ' . $number; + $limits = 'LIMIT ' . $number; } else { - $limit = ''; + $limits = ''; } - $where = "WHERE $approved"; + if ( $count ) + $fields = 'COUNT(*)'; + else + $fields = '*'; + + $join = ''; + $where = $approved; if ( ! empty($post_id) ) $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); @@ -318,15 +324,17 @@ class WP_Comment_Query extends WP_Object_Query { if ( '' !== $search ) $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) ); - $pieces = array( 'where', 'orderby', 'order', 'limit' ); + $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); foreach ( $pieces as $piece ) $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; - if ( $count ) - return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments $where ORDER BY $orderby $order $limit" ); + $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where ORDER BY $orderby $order $limits"; - $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $where ORDER BY $orderby $order $limit" ); + if ( $count ) + return $wpdb->get_var( $query ); + + $comments = $wpdb->get_results( $query ); $comments = apply_filters_ref_array( 'the_comments', array( $comments, &$this ) ); wp_cache_add( $cache_key, $comments, 'comment' );