+add_filter( 'pre_get_posts', 'w_sticky_posts' );
+function w_sticky_posts($q) {
+ $q->set('ppp_include_sticky',true);
add_filter( 'the_posts', 'sticky_count_offset', 10, 2 );
function sticky_count_offset( $posts, $q ) {
if ( $q->get( 'ppp_include_sticky' )
-add_filter( 'pre_get_posts', 'sticky_count_on_paged' );
-function sticky_count_on_paged( $q ) {
+function is_paged_home_with_sticky( $q ) {
&& $q->get( 'ppp_include_sticky' )
- && false == $q->get( 'ignore_sticky_posts' ) ) {
+ && false == $q->get( 'ignore_sticky_posts' );
+add_filter( 'pre_get_posts', 'sticky_count_on_paged', 20 );
+function sticky_count_on_paged( $q ) {
+ if ( is_paged_home_with_sticky( $q ) ) {
+ $q->set('post__not_in', get_option( 'sticky_posts', array() ) );
$offset = count( get_option( 'sticky_posts', array() ) );
- $page_offset = $offset + ( ( $q->get( 'paged' ) -1 ) * $q->get( 'posts_per_page' );
+ $page_offset = $q->get( 'posts_per_page', get_option( 'posts_per_page' ) ) * ( $q->get( 'paged' ) -1 ) - $offset;
$q->set( 'offset', $page_offset );
+add_filter( 'found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
+function myprefix_adjust_offset_pagination( $found_posts, $q ) {
+ if ( is_paged_home_with_sticky( $q ) ) {
+ $offset = count( get_option( 'sticky_posts', array() ) );
+ return $found_posts + $offset;