• Hi, so I’m trying to get wordpress pagination to work on my page. The page is entirely custom, and I have hand coded the while loop that displays the posts. The problem however, is that when one clicks on the next page to see the older entries, it displays the same posts that were on the original page.

    Here is my code, could anyone help me out or point out what I am doing wrong?

    <?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    // args
    $args = array(
    	'posts_per_page' => 3,
    	'post_type'=> 'post',
    	'category_name' => 'premium-news-updates',
    	'paged' => ''
    );
    // get results
    $the_query = new WP_Query( $args );
    // The Loop
    ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul class="frontnewsul">
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<li class="frontnewsli">
    			<a href="<?php the_permalink(); ?>"><div class="stksymnewshdln"><?php the_field('symbol'); ?></div><span class="membernewslink"><?php the_title(); ?></span></a>
    		</li>
    
    		<div class="member-news-the_content">
    		<?php the_content(); ?>
    		</div>
    
    	<?php endwhile; ?>
    	</ul>	
    
    		<?php
    next_posts_link( 'Older Entries', $the_query->max_num_pages );
        previous_posts_link( 'Newer Entries' );
    ?>
    		  <?php
        // clean up after our query
        wp_reset_postdata();
        ?>
    
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
Viewing 1 replies (of 1 total)
  • Thread Starter phpchick

    (@phpchick)

    I figured it out.

    I didn’t put the $page variable, back into the $args array

    the corresponding part should have looked like this

    $args = array(
    	'posts_per_page' => 3,
    	'post_type'=> 'post',
    	'category_name' => 'premium-news-updates',
    	'paged' => $paged
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Pagination not working – shows the same posts on first page’ is closed to new replies.