I've enabled pagination for one of my pages where I'm pulling the latest news articles from. This is the code:
<div class="container white" style="padding:50px 0;">
<div class="container-max">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1';
$args = array(
'numberposts' => 5,
'offset' => 2,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'cat'=>'-8, -9, -7, -6, -5, -4',
'paged'=> $paged
);
$postslist = get_posts( $args );
?>
<div class="latest_new_posts main-news">
<?php
$wp_query = new WP_Query('$args'.$paged);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : the_post();
foreach ($postslist as $post) : setup_postdata($post);
?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="position:relative; margin:45px 0;" > <div class="blog-date-news main-news-date"><span><?php the_date('d/m/Y'); ?></span></div> <div class="blog-container main-news-container"> <div class="news-blog-title"><span><?php the_title(); ?></span></div> <div class="news-blog-excerpt"> <?php echo excerpt(500); ?> </div> <div class="news-blog-more main-news-blog-more"><a href="<?php the_permalink(); ?>"> <img src=""/></a></div> </div> </div>
<?php
endforeach;
endwhile;
?>
As you can see I've set 'offset' => 2
as the first 2 posts shouldn't be displayed. Now this work, however when you go to the second page the last 2 posts from the first page show again.
So for example I've got 4 posts on page 1:
Post A, Post B, Post C and Post D
On the second page it will then show:
Post C, Post D, Post E, Post F
This doesn't happen when you go from the second to the third page.
Anybody know how to fix this?