Ticket #11398: 11398.2.diff
| File 11398.2.diff, 3.2 KB (added by , 13 years ago) |
|---|
-
tests/tests/query/results.php
369 369 'child-two', 370 370 ), wp_list_pluck( $posts, 'post_title' ) ); 371 371 } 372 373 /** 374 * @ticket 11398 375 */ 376 function test_query_orderby_comment_date() { 377 $post_date = '2013-08-02 14:15:04'; 378 $one = $this->factory->post->create( array( 'post_title' => 'one', 'post_date' => $post_date ) ); 379 $two = $this->factory->post->create( array( 'post_title' => 'two', 'post_date' => $post_date ) ); 380 $three = $this->factory->post->create( array( 'post_title' => 'three', 'post_date' => $post_date ) ); 381 $four = $this->factory->post->create( array( 'post_title' => 'four', 'post_date' => $post_date ) ); 382 383 $this->factory->comment->create_post_comments( $three, 1, array( 'comment_date' => '2013-08-02 14:15:05' ) ); 384 $this->factory->comment->create_post_comments( $two, 1, array( 'comment_date' => '2013-08-02 14:15:06' ) ); 385 $this->factory->comment->create_post_comments( $one, 1, array( 'comment_date' => '2013-08-02 14:15:07' ) ); 386 387 $asc_posts = $this->q->query( array( 388 'post__in' => array( $one, $two, $three, $four ), 389 'orderby' => 'comment_date', 390 'order' => 'ASC' 391 ) ); 392 393 $this->assertEquals( array( 394 'three', 395 'two', 396 'one', 397 'four', 398 ), wp_list_pluck( $asc_posts, 'post_title' ) ); 399 400 $desc_posts = $this->q->query( array( 401 'post__in' => array( $one, $two, $three, $four ), 402 'orderby' => 'comment_date', 403 'order' => 'DESC' 404 ) ); 405 406 $this->assertEquals( array( 407 'one', 408 'two', 409 'three', 410 'four', 411 ), wp_list_pluck( $desc_posts, 'post_title' ) ); 412 } 372 413 } -
src/wp-includes/query.php
Property changes on: tests/data ___________________________________________________________________ Added: svn:ignore + .trac-ticket-cache.core.trac.wordpress.org .trac-ticket-cache.unit-tests.trac.wordpress.org Property changes on: src ___________________________________________________________________ Added: svn:ignore + .wp-tests-version
2361 2361 $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; 2362 2362 } else { 2363 2363 // Used to filter values 2364 $allowed_keys = array( 'name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count');2364 $allowed_keys = array( 'name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count', 'comment_date' ); 2365 2365 if ( !empty($q['meta_key']) ) { 2366 2366 $allowed_keys[] = $q['meta_key']; 2367 2367 $allowed_keys[] = 'meta_value'; … … 2396 2396 case 'comment_count': 2397 2397 $orderby = "$wpdb->posts.comment_count"; 2398 2398 break; 2399 case 'comment_date': 2400 $orderby = "ISNULL($wpdb->comments.comment_date), $wpdb->comments.comment_date"; 2401 $join .= " LEFT JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID "; 2402 break; 2399 2403 default: 2400 2404 $orderby = "$wpdb->posts.post_" . $orderby; 2401 2405 }