Offset breaking pagination on custom query
-
Hey guys, hoping you can help here. I’ve added an offset of -1 and I’ve set posts per page to 2 to show you whats going on. I’m using Blankslate theme with ACF.
So as you can see from my link, theres a top header showing the latest post which works perfectly and I added <?php wp_reset_query(); ?> at the end of it so it doesn’t conflict with the bottom half. The bottom half however shows up but if you go to the next page it shows the same posts again??
If I take out the offset the pagination works normally as it should.
Here is my code for the bottom half:
<?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'posts_per_page' => 2, 'cat' => '3,4', 'paged' => $paged, 'offset' => 1 ); $custom_query = new WP_Query( $args ); ?> <?php if ( $custom_query->have_posts() ) : ?> <?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?> <?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?> <?php $class = (empty($class) ? 'class="alternate"' : '');?> <div id="bios-posts-single" <?php echo $class; ?>> <a href="<?php the_permalink(); ?>"> <img class="hidden" src="<?php echo $backgroundImg[0]; ?>"> <div class="bios-post-info"> <small>Bio: By <?php the_author(); ?></small> <h1 class="bios-post-h1"><?php the_title(); ?></h1> <? echo '<p class="post-excerpt">' . get_the_excerpt() . '</p>'; ?> <?php the_date('m-d-Y', '<h2>', '</h2>'); ?> </div> <div class="bios-post-img"> <img class="shown" src="<?php echo $backgroundImg[0]; ?>"> </div> </a> </div> <?php endwhile; ?> <div class="pagination"> <?php echo paginate_links( array( 'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ), 'total' => $custom_query->max_num_pages, 'current' => max( 1, get_query_var( 'paged' ) ), 'format' => '?paged=%#%', 'show_all' => false, 'type' => 'plain', 'end_size' => 2, 'mid_size' => 1, 'prev_next' => true, 'prev_text' => sprintf( '<i></i> %1$s', __( '<', 'text-domain' ) ), 'next_text' => sprintf( '%1$s <i></i>', __( '>', 'text-domain' ) ), 'add_args' => false, 'add_fragment' => '', ) ); ?> </div> <?php wp_reset_postdata();?> <?php else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>The page I need help with: [log in to see the link]
The topic ‘Offset breaking pagination on custom query’ is closed to new replies.