Hello guys, Can someone give me a little help here? I have this php code: <? $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $query_args = array( 'post_type' => 'vrvideo', 'posts_per_page' => 5, 'paged' => $paged ); $loop = new WP_Query( $query_args ); echo '<div class="crp_related "><ul>'; while ( $loop->have_posts() ) : $loop->the_post(); echo '<li><a href="', the_permalink(), '">', the_post_thumbnail('related-thumb'), '</a>'; echo '<span class="crp_title" style="bottom:4px;">'; if (strlen($post->post_title) > 27) { echo substr(the_title($before = '', $after = '', FALSE), 0, 27) . '...'; } else { the_title(); } echo '</span></li>'; endwhile; echo '</ul>'; echo '<div class="crp_clear"></div></div>'; ?> <?php if ($loop->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_next_posts_link( 'Older Entries', $loop->max_num_pages ); // display older posts link ?> </div> <div class="next-posts-link"> <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?> </div> </nav> <?php } ?> <?php wp_reset_postdata(); ?> PHP: In my page, I have 6 posts. The pagination appears fine and is showing 5 posts. Everything good here. The problem is that when I change page, is showing always the same 5 posts in all pages. What I did wrong? Could be the $loop->max_num_pages? HELP
Does it happen if you press both links or just for the one that's supposed to give you older posts? P.S. Your prev-posts-link class includes next posts and vice versa for the second one. Fix that first to avoid confusion.
Blank, here's an example: Page with 6 posts. When you enter in the page, appears 5 results (post1,post2,post3,post4,post5) and pagination below. When you click in Older Entries, appears exactly same 5 results (post1,post2,post3,post4,post5) instead of post6. And if you click in Older Entries again (page 3) appears exactly same results again... and so on... I tried to replace the code from: <?php if ($loop->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_next_posts_link( 'Older Entries', $loop->max_num_pages ); // display older posts link ?> </div> <div class="next-posts-link"> <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?> </div> </nav> <?php } ?> PHP: To: <?php // next_posts_link() usage with max_num_pages next_posts_link( 'Older Entries', $loop->max_num_pages ); previous_posts_link( 'Newer Entries' ); ?> PHP: Works exactly with same issue, so probably the issue is in the code above.
<?php if ($loop->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_previous_posts_link( 'Older Entries', $loop->max_num_pages ); // display older posts link ?> </div> <div class="next-posts-link"> <?php echo get_next_posts_link( 'Newer Entries' ); // display newer posts link ?> </div> </nav> <?php } ?> PHP: And this?
What? I just swapped links, that's all. If it breaks there, there must be something completely wrong in the core, not the given snippet. What is $loop->max_num_pages returning (just echo it)?
Yeah that's weird hehe Here goes the echo of: <?php echo $loop->max_num_pages; ?> PHP: Returning: 2 Code (markup): With this code only appears 2 pages as should be: <?php // next_posts_link() usage with max_num_pages next_posts_link( 'Older Entries', $loop->max_num_pages ); previous_posts_link( 'Newer Entries' ); ?> PHP: The problem is that is always showing same results in 2nd page... The issue must be here somewhere: $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $query_args = array( 'post_type' => 'vrvideo', 'posts_per_page' => 5, 'paged' => $paged ); $loop = new WP_Query( $query_args ); PHP:
Try adding wp_reset_query() after all of the queries called. That's all I can think of w/o having access to given files/website (feel free to PM me though if you are open to share those details; no cost whatsover).
Hey, I solved the problem I replaced this line: 'paged' => $paged PHP: With this one: 'paged' => get_query_var( 'paged' ) PHP: Now is working perfectly. Thank you anyway for trying to help me
The reason that worked was that you used the wrong name for the call in the get_query_var() when you assigned it to the $paged-variable - you used 'page' inside those, but you used 'paged' in the one that works...