Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Offset breaks pagination Reply To: Offset breaks pagination

#10284
Tom
Keymaster

That fix might be the best method.

An alternative is this function, but I’m not 100% confident it will work:

add_filter( 'pre_get_posts', function( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $offset = 2;
        $ppp = get_option('posts_per_page');

        if ( $query->is_paged ) {
            $page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
            $query->set('offset', $page_offset );
        } else {
            $query->set('offset',$offset);
        }
    } else {
        return $query;
    }
} );