0

Switching a loop on a static front page from query_posts to wp_query. All is working other than the pagination link (which used to work). Example can be seen live here in "work" section.

Here is my loop:

    <?php
     $paged = (get_query_var('page')) ? get_query_var('page') : 1;
     $args = array('category_name'=>'portfolio','posts_per_page'=>4,'paged'=>$paged);
     $work_posts = new WP_Query($args);

     if($work_posts->have_posts()) : 
        while($work_posts->have_posts()) : 
           $work_posts->the_post();
    ?>

        <div class="box">
        <div class="thumbnail">
            <a href="<?php the_permalink(); ?>">
            <?php
                if ( has_post_thumbnail() ) {
                the_post_thumbnail();
                }   
            ?>  
            </a>
        </div><!-- THUMBNAIL -->        
        <aside>
          <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
        </aside><!-- ASIDE -->
        </div><!-- BOX -->

    <?php endwhile; ?>
  </div><!-- WORK ITEMS -->

  <div class="navigation">
    <div class="older">
      <?php next_posts_link('load more'); ?>
    </div>
  </div>

  <?php wp_reset_postdata(); ?>

    <?php else : ?>
        <h2>Sorry, there are no posts to display</h2>
    <?php endif; ?> 
0

See the example on next_posts_link in Codex. You have to pass the max_num_pages to the function, otherwise it uses the value from the global $wp_query, which is no longer the correct query object now that you've created a custom query object.

next_posts_link( 'load more', $work_posts->max_num_pages );
1
  • This worked perfectly. Not sure how I missed that in the codex, thanks! – mtthwbsh Jan 1 '14 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.