diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 5ef51b50a1..4600dc93e8 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2786,13 +2786,13 @@ class WP_Query { if ( !$page ) $page = 1; - if ( empty($q['offset']) ) { - $pgstrt = ($page - 1) * $q['posts_per_page'] . ', '; - } else { // we're ignoring $page and using 'offset' + $pgstrt = ($page - 1) * $q['posts_per_page']; + + if ( ! empty( $q['offset'] ) ) { $q['offset'] = absint($q['offset']); - $pgstrt = $q['offset'] . ', '; + $pgstrt += $q['offset']; } - $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; + $limits = 'LIMIT ' . $pgstrt . ', ' . $q['posts_per_page']; } // Comments feeds diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 404aea6720..72ebeee786 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -278,9 +278,6 @@ class Tests_Query_Results extends WP_UnitTestCase { $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); } - /** - * @ticket 18897 - */ function test_query_offset_and_paged() { $posts = $this->q->query('paged=2&offset=3');