Make WordPress Core


Ignore:
Timestamp:
09/25/2015 04:25:20 AM (8 years ago)
Author:
boonebgorges
Message:

Introduce 'paged' parameter for WP_User_Query.

This is an alternative to using 'offset', and manually calculating pagination.
Note that 'paged' works only in conjunction with 'number', the latter of which
provides the per-page value.

Props sebastian.pisula.
Fixes #25145.

File:
1 edited

Legend:

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

    r32713 r34531  
    460460        $query->prepare_query( array( 'number' => 8 ) );
    461461        $this->assertNotEmpty( $query->query_limit );
    462         $this->assertEquals( 'LIMIT 8', $query->query_limit );
     462        $this->assertEquals( 'LIMIT 0, 8', $query->query_limit );
    463463
    464464        // All values get reset
     
    858858        $this->assertEqualSets( $expected, $found );
    859859    }
     860
     861    /**
     862     * @ticket 25145
     863     */
     864    public function test_paged() {
     865        $users = $this->factory->user->create_many( 5 );
     866
     867        $q = new WP_User_Query( array(
     868            'number' => 2,
     869            'paged' => 2,
     870            'orderby' => 'ID',
     871            'order' => 'DESC', // Avoid funkiness with user 1.
     872            'fields' => 'ids',
     873        ) );
     874
     875        $this->assertEquals( array( $users[2], $users[1] ), $q->results );
     876    }
    860877}
Note: See TracChangeset for help on using the changeset viewer.