WordPress.org

Make WordPress Core

Changeset 26012


Ignore:
Timestamp:
11/05/2013 01:34:44 AM (7 years ago)
Author:
wonderboymusic
Message:

Respect paged when offset is used in WP_Query. Adds unit tests.

Props coffee2code.
Fixes #18897.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r26007 r26012  
    27872787                $page = 1;
    27882788
    2789             if ( empty($q['offset']) ) {
    2790                 $pgstrt = ($page - 1) * $q['posts_per_page'] . ', ';
    2791             } else { // we're ignoring $page and using 'offset'
     2789            $pgstrt = ($page - 1) * $q['posts_per_page'];
     2790
     2791            if ( ! empty( $q['offset'] ) ) {
    27922792                $q['offset'] = absint($q['offset']);
    2793                 $pgstrt = $q['offset'] . ', ';
    2794             }
    2795             $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
     2793                $pgstrt += $q['offset'];
     2794            }
     2795            $limits = 'LIMIT ' . $pgstrt . ', ' . $q['posts_per_page'];
    27962796        }
    27972797
  • trunk/tests/phpunit/tests/query/results.php

    r25356 r26012  
    279279    }
    280280
    281     /**
    282      * @ticket 18897
    283      */
    284281    function test_query_offset_and_paged() {
    285282        $posts = $this->q->query('paged=2&offset=3');
Note: See TracChangeset for help on using the changeset viewer.