Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20227 closed defect (bug) (invalid)

query_posts and is_archive conflicts

Reported by: nhuja's profile nhuja Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


When I add query_posts is category.php (twentyeleven) just before the while loop

<?php query_posts('posts_per_page=20' ); ?>

Then in content.php (for standard post)

instead of

<?php if ( is_search() ) : Only display Excerpts for Search ?>

This works fine. Replace it by

<?php if ( is_archive() ) : Only display Excerpts for Archive pages ?>

It doesn't show excerpt.

Interestingly, when using

<?php $my_query = new WP_Query('posts_per_page=20'); ?>

is_archive seems to work.

Change History (2)

#1 @scribu
12 years ago

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

Please use the support forums for such issues:

#2 @dd32
12 years ago

To explain the above..

The behavior you're seeing is correct. query_posts() replaces the current page query, this affects all query flags, post contents, and any other request-context there is. Creating a new WP_Query instance however (or using get_posts()), keeps all those properties contained to the instance of WP_Query.

Note: See TracTickets for help on using tickets.