Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#14610 closed defect (bug) (wontfix)

WP_query does() not generate next_posts_link()

Reported by: jonshipman's profile jonshipman Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.0
Component: Query Keywords:
Focuses: Cc:

Description

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.

Change History (2)

#1 @mdawaffe
13 years ago

previous_posts_link() shows since we're already on page/2, so it knows there's a page/1 to go to.

next_posts_link() shows nothing for new WP_Query since it's based on the global query.

query_posts() sets the global query, so fixes the issue.

I think this is pretty edge.

#2 @nacin
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Agreed.

Note: See TracTickets for help on using tickets.