Make WordPress Core


Ignore:
Timestamp:
04/17/2016 03:16:36 AM (8 years ago)
Author:
boonebgorges
Message:

Query: Allow results to be ordered by post_parent__in.

Props postpostmodern.
Fixes #36515.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/query.php

    r37224 r37225  
    179179    }
    180180
     181    /**
     182     * @ticket 36515
     183     */
     184    public function test_post_name__in_ordering() {
     185        $post_id1 = self::factory()->post->create( array( 'post_name' => 'id-1', 'post_type' => 'page' ) );
     186        $post_id2 = self::factory()->post->create( array( 'post_name' => 'id-2', 'post_type' => 'page' ) );
     187        $post_id3 = self::factory()->post->create( array(
     188            'post_name' => 'id-3',
     189            'post_type' => 'page',
     190            'post_parent' => $post_id2
     191        ) );
     192
     193        $ordered = array( 'id-2', 'id-3', 'id-1' );
     194
     195        $q = new WP_Query( array(
     196            'post_type' => 'any',
     197            'post_name__in' => $ordered,
     198            'orderby' => 'post_name__in'
     199        ) );
     200
     201        $this->assertSame( $ordered, wp_list_pluck( $q->posts, 'post_name' ) );
     202    }
     203
    181204    function test_post_status() {
    182205        $statuses1 = get_post_stati();
Note: See TracChangeset for help on using the changeset viewer.