mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-07 09:49:04 +00:00
Apply order to each passed value for orderby in WP_Query:
* Since `orderby` in `WP_Query` can accept space-delimited sets, yet only one `order` value: when multiple values are passed (and `DESC` is the order), the default sort order `ASC` is being applied to all values before the last in the set. * There is a unit test that sporadically fails since 3.6 in `tests/post/revision` due to multiple posts having the same `post_date` from being added so rapidly * When ordering revisions in `wp_get_post_revisions()`, order by `post_date ID` * Change the `order` value in `wp_get_post_revisions()` to `ASC`. This will produce SQL like: `ORDER BY $wpdb->posts.post_date ASC, $wpdb->posts.ID ASC`. Previously, this would have produced SQL like: `ORDER BY $wpdb->posts.post_date DESC`, and with the addition of ` ID`: `ORDER BY $wpdb->posts.post_date ASC, $wpdb->posts.ID DESC`. Clearly, wrong. The original SQL produced: `ORDER BY $wpdb->posts.post_date DESC`. As such, return the reversions in reverse order using `array_reverse()`. Not doing so would break "Preview Changes." * Add unit tests to assert that all of this works. * All existing unit tests pass with the change to ordering multiple `orderby`s in `WP_Query`. * In the future, we should support independent `order` for each `orderby`, see #17065. Props SergeyBiryukov, wonderboymusic. Fixes #26042. git-svn-id: https://develop.svn.wordpress.org/trunk@28541 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -338,4 +338,51 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
|
||||
$this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 26042
|
||||
*/
|
||||
function test_wp_get_posts_revisions_sql() {
|
||||
$post = get_default_post_to_edit( 'post', true );
|
||||
|
||||
add_filter( 'query', array( $this, '_filter_query' ) );
|
||||
|
||||
wp_get_post_revisions( $post->ID );
|
||||
}
|
||||
|
||||
function _filter_query( $sql ) {
|
||||
remove_filter( 'query', array( $this, '_filter_query' ) );
|
||||
global $wpdb;
|
||||
$this->assertContains( "ORDER BY $wpdb->posts.post_date ASC, $wpdb->posts.ID ASC", $sql );
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 26042
|
||||
*/
|
||||
function test_revision_order() {
|
||||
$ok = 0;
|
||||
$reversed = 0;
|
||||
|
||||
for ( $i = 0; $i < 100; $i++ ) {
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
|
||||
|
||||
for ( $j = 1; $j < 3; $j++ ) {
|
||||
wp_update_post( array( 'post_content' => 'updated post' . $j , 'ID' => $post_id ) );
|
||||
}
|
||||
|
||||
$revisions = wp_get_post_revisions( $post_id );
|
||||
$first = array_shift( $revisions );
|
||||
$last = array_pop( $revisions );
|
||||
|
||||
if ( $first->ID < $last->ID ) {
|
||||
$reversed++;
|
||||
} else {
|
||||
$ok++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals( 100, $ok );
|
||||
$this->assertEquals( 0, $reversed );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user