[wp-trac] [WordPress Trac] #14610: WP_query does() not generate next_posts_link()

WordPress Trac wp-trac at lists.automattic.com
Fri Aug 13 20:51:04 UTC 2010


#14610: WP_query does() not generate next_posts_link()
--------------------------+-------------------------------------------------
 Reporter:  jonshipman    |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  3.0            
 Severity:  minor         |    Keywords:                 
--------------------------+-------------------------------------------------
 Using the following code, WP_query does not seem to generate an 'Older
 Entries' link.
 However if I type /page/2 in the address bar previous_posts_link() does
 work (still no change to next_posts_link()).

 {{{
 <?
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
                 'posts_per_page' => 1,
                 'category_name' => 'Portfolio',
                 'paged' => $paged
    );
    $portfolio_q = new WP_Query($args);
    while ($portfolio_q->have_posts()) :
           $portfolio_q->the_post(); ?>

           <div class="box" id="post-<?php the_ID(); ?>">
                   <? the_excerpt('Read More');?>
           </div>


 <? endwhile; ?>

                 <div class="blognavigation">
                         <div class="alignleft"><?php
 next_posts_link('&laquo; Older Entries') ?></div>
                         <div class="alignright"><?php
 previous_posts_link('Newer Entries &raquo;') ?></div>
                 </div>

 </div>
 }}}

 This next bit of code I've taken out WP_query and replaced it with
 query_posts() and it works as expected.

 {{{
 <?
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
                 'posts_per_page' => 4,
                 'category_name' => 'Portfolio',
                 'paged' => $paged
    );
    query_posts($args);
    while (have_posts()) :
          the_post(); ?>

           <div class="box" id="post-<?php the_ID(); ?>">
                   <? the_excerpt('Read More');?>
           </div>


 <? endwhile; ?>

                 <div class="blognavigation">
                         <div class="alignleft"><?php
 next_posts_link('&laquo; Older Entries') ?></div>
                         <div class="alignright"><?php
 previous_posts_link('Newer Entries &raquo;') ?></div>
                 </div>

 <? wp_reset_query(); ?>
 }}}

 The only issue I see is if WP_query isn't suppose to generate a
 next_posts_link, why is it generating the previous_posts_link?

 Not a big bug, but it's a discrepancy that needs to be addressed.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14610>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list