Forums

[resolved] Paging - wrong results (3 posts)

  1. martin.bethann
    Member
    Posted 11 months ago #

    I have the following code and the paging works great after I added the fix found here. However, the returned posts are wrong. I have 4 posts total and it shows same thing on both pages - the latest 3 posts. Any ideas? Thanks!!

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	   $loop = new WP_Query( array(
    		'post_type' => 'make-your-look',
    		'paged=' => $paged,
    		'posts_per_page' => 3 // get all posts
    		));   
    
    		if ($loop->have_posts()) : while ( $loop->have_posts() ) : $loop->the_post();
    		?>
    
        <div id="post-<?php the_ID(); ?>" class="post">
          content here...
        </div>
        <?php
        endwhile; ?>
    
        <?php
    	global $wp_query;
    	$clone_page_total = $wp_query->max_num_pages;
            $wp_query->max_num_pages = $loop->max_num_pages;
    	if($wp_query->max_num_pages > 1){
              posts_nav_link();
            }
            $wp_query->max_num_pages = $clone_page_total; ?>
    
        <?php else : ?>
        <?php endif; ?>
  2. martin.bethann
    Member
    Posted 11 months ago #

    Please... could someone point me in the right direction? Thanks!!

  3. martin.bethann
    Member
    Posted 11 months ago #

    For those pulling their hair out, this is what solved the issue for me... although, I'd still like to know what is wrong with the original call:

    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=make-your-look&posts_per_page=3'.'&paged='.$paged);
    if ($wp_query->have_posts()) : while ( $wp_query->have_posts() ) : $wp_query->the_post();  ?>
    ...
    <?php endwhile; ?>
    <?php if($wp_query->max_num_pages > 1){
       		posts_nav_link();
          } ?>
    <?php $wp_query = null; $wp_query = $temp;?>
    <?php else : ?>
    <?php endif; ?>

Reply

You must log in to post.

About this Topic