Make WordPress Core

Ticket #12668: 12668-comments-query.4.patch

File 12668-comments-query.4.patch, 1.6 KB (added by dancameron, 10 years ago)

noticed how I created confusion by removing the check for the comment type.

  • src/wp-includes/comment.php

     
    131131 * @uses $wpdb
    132132 *
    133133 * @param int $post_id The ID of the post
     134 * @param array $args WP_Comment_Query args
    134135 * @return array $comments The approved comments
    135136 */
    136 function get_approved_comments($post_id) {
    137         global $wpdb;
    138         return $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
     137function get_approved_comments( $post_id = 0, $args = array() ) {
     138        $defaults = array(
     139                'status' => 1,
     140                'post_id' => $post_id
     141        );
     142        $r = wp_parse_args( $args, $defaults );
     143
     144        $query = new WP_Comment_Query;
     145        return $query->query( $r );
    139146}
    140147
    141148/**
     
    447454                } elseif( 'pings' == $this->query_vars['type'] ) {
    448455                        $where .= ' AND comment_type IN ("pingback", "trackback")';
    449456                } elseif ( ! empty( $this->query_vars['type'] ) ) {
    450                         $where .= $wpdb->prepare( ' AND comment_type = %s', $this->query_vars['type'] );
     457                        if ( is_array( $this->query_vars['type'] ) ) {
     458                                if( in_array( 'comment', $this->query_vars['type'] ) ) {
     459                                        // Default comments don't have an explicit type
     460+                                       $this->query_vars['type'][] = '';
     461+                               }
     462                                $where .= ' AND comment_type IN (' . implode( ',', array_map( 'esc_sql', $this->query_vars['type'] ) . ')';
     463                        } else {
     464                                $where .= $wpdb->prepare( ' AND comment_type = %d', $this->query_vars['type'] );
     465                        }
    451466                }
    452467
    453468                if ( '' !== $this->query_vars['parent'] ) {