offset query issue on pagination

wordpress

#1

Hi Devs,

I know this is an easy fix for you but I am struggling on this as it’s my first time to encounter this issue. I have a custom page template name “blog” then on this page, I have this code (below)

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'post', 'offset' => 1, 'post_status' => 'publish', 'paged' => $paged );
$query = new WP_Query( $args ); 

if ( $query->have_posts() ) :
   while ( $query->have_posts() ) : $query->the_post();
   endwhile;
endif; 

previous_posts_link( esc_html__( 'Previous', 'textdomain' ) );
next_posts_link( esc_html__( 'Next', 'textdomain' ), $query->max_num_pages ); 

Offset works fine when displaying. My issue is previous_posts_link and next_posts_link is not working fine it goes directly to page/2 but the list I’m seeing is still page/1
Can anyone help me on this?

Thanks


#2

Hi, Put this code into functions.php

if ( ! function_exists( 'pagination_fix' ) ) :
    function pagination_fix( $redirect ) {
        if (is_front_page() ) {

            $redirect = false;
        }
        return $redirect;
    }

    add_filter( 'redirect_canonical', 'pagination_fix' );
endif;