[wp-trac] [WordPress Trac] #27142: Issues with pagination when offset is set
WordPress Trac
noreply at wordpress.org
Mon Feb 17 15:33:14 UTC 2014
#27142: Issues with pagination when offset is set
-------------------------------+------------------------------
Reporter: alkinfotech | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.8.1
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by alkinfotech):
The issue is identified with the code at wp-includes/query.php.
The paging code is as follows:
if ( empty($q['nopaging']) && !$this->is_singular ) {
$page = absint($q['paged']);
if ( !$page )
$page = 1;
if ( empty($q['offset']) ) {
$pgstrt = ($page - 1) * $q['posts_per_page'] . ', ';
} else { // we're ignoring $page and using 'offset'
$q['offset'] = absint($q['offset']);
$pgstrt = $q['offset'] . ', ';
}
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
}
Note, when offset is there, $pgstrt = $q['offset'] . ', ';
That means eg. offset = 4, the pgstrt will always be 4 and hence the limit
will be LIMIT 4,[posts_per_page], irrespective of the page selected.
The solution is to modify this line as :
$pgstrt = $q['offset'] + ($page - 1) * $q['posts_per_page'] . ', ';
So for page = 2, offset = 4 & posts_per_page = 10, pgstrt = 14 & limit
will be LIMIT 14,10 which will be ideal for page 2 with offset 4.
I am currently using this and it is working perfectly fine.
Wanted to raise the bug so that in the next release, it is covered up.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/27142#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list