[wp-trac] [WordPress Trac] #18897: query_posts / WP_query parameter 'offset' should play nicely with 'paged'
WordPress Trac
noreply at wordpress.org
Fri Nov 29 22:33:33 UTC 2013
#18897: query_posts / WP_query parameter 'offset' should play nicely with 'paged'
------------------------------------------+-----------------------------
Reporter: here | Owner: wonderboymusic
Type: enhancement | Status: reopened
Priority: normal | Milestone: 3.8
Component: Query | Version: 3.2.1
Severity: normal | Resolution:
Keywords: has-patch commit needs-codex |
------------------------------------------+-----------------------------
Comment (by bradyvercher):
You're not using `offset` in that code, which is why the behavior isn't
different. Previously, it was possible by manually calculating the offset
based on the current page. The second page of results with the snippet
below would show results 5-15. Now it will show results 15-25.
{{{
function change_posts_per_page_18897( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( $query->is_paged() ) {
$query->set( 'posts_per_page', 10 );
$query->set( 'offset', ( $query->get( 'paged' ) - 1 ) * 10
- 5 );
} else {
$query->set( 'posts_per_page', 5 );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page_18897' );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18897#comment:17>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list