+ } elseif ( ! empty( $this->query_vars['type'] ) ) {
+ $where .= $wpdb->prepare( ' AND comment_type = %s', $this->query_vars['type'] );
+ }
+
+ if ( '' !== $this->query_vars['parent'] ) {
+ $where .= $wpdb->prepare( ' AND comment_parent = %d', $this->query_vars['parent'] );
+ }
+
+ if ( is_array( $this->query_vars['user_id'] ) ) {
+ $where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
+ } elseif ( '' !== $this->query_vars['user_id'] ) {
+ $where .= $wpdb->prepare( ' AND user_id = %d', $this->query_vars['user_id'] );
+ }
+
+ if ( '' !== $this->query_vars['search'] ) {
+ $where .= $this->get_search_sql(
+ $this->query_vars['search'],
+ array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
+ );
+ }
+
+ $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type' ) );
+ $post_fields = array_filter( $plucked );
+
+ if ( ! empty( $post_fields ) ) {
+ $join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
+ foreach( $post_fields as $field_name => $field_value )
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value );
+ }
+
+ if ( ! empty( $this->meta_query->queries ) ) {
+ $clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
+ $join .= $clauses['join'];
+ $where .= $clauses['where'];
+ $groupby = "{$wpdb->comments}.comment_ID";
+ }
+
+ $date_query = $this->query_vars['date_query'];
+ if ( ! empty( $date_query ) && is_array( $date_query ) ) {
+ $date_query_object = new WP_Date_Query( $date_query, 'comment_date' );
+ $where .= $date_query_object->get_sql();