Make WordPress Core


Ignore:
Timestamp:
01/08/2019 03:32:04 AM (6 years ago)
Author:
boonebgorges
Message:

Query: Standardize treatment of 'orderby' values post__in, post_parent__in, and post_name__in.

Ordering by post__in was introduced in [21776], but the code assumed that
post__in would be a comma-separated string listing post IDs. When an array
of post IDs was passed to the post__in query var, 'orderby=postin' was
not respected. This changeset changes this behavior by handling
'orderby=post
in' in the same way as most other values of 'orderby',
which ensures that arrays as well as strings can be properly parsed.

The same treatment is given to the similar post_name__in and
post_parent__in options of 'orderby', so that most query generation for
orderby clauses happens in the same place, instead of in special cases.

A slight change in the resulting SQL (related to the whitespace around
parentheses and commas) necessitates a change to an existing REST API test
that does a string comparison against the SQL query.

Props mgibbs189, kelvink.
Fixes #38034.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r44394 r44452  
    292292        $this->assertEquals( 2, count( $data ) );
    293293        $this->assertEquals( $id1, $data[0]['id'] );
    294         $this->assertPostsOrderedBy( "FIELD( {posts}.ID, $id1,$id3 )" );
     294        $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id3)" );
    295295        // Invalid include should error
    296296        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
Note: See TracChangeset for help on using the changeset viewer.