Changeset 29045
- Timestamp:
- 07/09/2014 06:15:42 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r28922 r29045 246 246 $defaults = array( 247 247 'author_email' => '', 248 'fields' => '', 248 249 'ID' => '', 249 250 'karma' => '', … … 369 370 $fields = 'COUNT(*)'; 370 371 } else { 371 $fields = '*'; 372 } 372 switch ( strtolower( $this->query_vars['fields'] ) ) { 373 case 'ids': 374 $fields = "$wpdb->comments.comment_ID"; 375 break; 376 default: 377 $fields = "*"; 378 break; 379 } 380 } 381 373 382 $join = ''; 374 383 $where = $approved; … … 461 470 return $wpdb->get_var( $query ); 462 471 } 472 473 if ( 'ids' == $this->query_vars['fields'] ) { 474 $this->comments = $wpdb->get_col( $query ); 475 return array_map( 'intval', $this->comments ); 476 } 477 463 478 $results = $wpdb->get_results( $query ); 464 479 /** -
trunk/tests/phpunit/tests/comment/query.php
r27258 r29045 181 181 182 182 } 183 184 /** 185 * @ticket 28434 186 */ 187 function test_fields_ids_query() { 188 $comment_1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); 189 $comment_2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); 190 $comment_3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); 191 192 // Ensure we are dealing with integers, and not objects. 193 $this->assertInternalType( 'integer', $comment_1 ); 194 $this->assertInternalType( 'integer', $comment_2 ); 195 $this->assertInternalType( 'integer', $comment_3 ); 196 197 $comment_ids = get_comments( array( 'fields' => 'ids' ) ); 198 $this->assertCount( 3, $comment_ids ); 199 $this->assertEquals( array( $comment_1, $comment_2, $comment_3 ), $comment_ids ); 200 } 183 201 }
Note: See TracChangeset
for help on using the changeset viewer.