WP_Query
should not ignore an offset of 0
.
Props mazurstas. Fixes #34060. git-svn-id: https://develop.svn.wordpress.org/trunk@34697 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3b7187eade
commit
49063d8e14
@ -3123,11 +3123,12 @@ class WP_Query {
|
|||||||
if ( !$page )
|
if ( !$page )
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
if ( empty($q['offset']) ) {
|
// If 'offset' is provided, it takes precedence over 'paged'.
|
||||||
$pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', ';
|
if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) {
|
||||||
} else { // we're ignoring $page and using 'offset'
|
$q['offset'] = absint( $q['offset'] );
|
||||||
$q['offset'] = absint($q['offset']);
|
|
||||||
$pgstrt = $q['offset'] . ', ';
|
$pgstrt = $q['offset'] . ', ';
|
||||||
|
} else {
|
||||||
|
$pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', ';
|
||||||
}
|
}
|
||||||
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
|
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
|
||||||
}
|
}
|
||||||
|
@ -459,4 +459,42 @@ class Tests_Query extends WP_UnitTestCase {
|
|||||||
public function filter_parse_query_to_modify_queried_post_id( $query ) {
|
public function filter_parse_query_to_modify_queried_post_id( $query ) {
|
||||||
$post = get_queried_object();
|
$post = get_queried_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 34060
|
||||||
|
*/
|
||||||
|
public function test_offset_0_should_override_page() {
|
||||||
|
$q = new WP_Query( array(
|
||||||
|
'paged' => 2,
|
||||||
|
'posts_per_page' => 5,
|
||||||
|
'offset' => 0,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertContains( 'LIMIT 0, 5', $q->request );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 34060
|
||||||
|
*/
|
||||||
|
public function test_offset_should_be_ignored_when_not_set() {
|
||||||
|
$q = new WP_Query( array(
|
||||||
|
'paged' => 2,
|
||||||
|
'posts_per_page' => 5,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertContains( 'LIMIT 5, 5', $q->request );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 34060
|
||||||
|
*/
|
||||||
|
public function test_offset_should_be_ignored_when_passed_a_non_numeric_value() {
|
||||||
|
$q = new WP_Query( array(
|
||||||
|
'paged' => 2,
|
||||||
|
'posts_per_page' => 5,
|
||||||
|
'offset' => '',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertContains( 'LIMIT 5, 5', $q->request );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user