Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 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:

Description

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
13 years ago

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

Please use the support forums for such issues:

http://wordpress.org/support/forum/how-to-and-troubleshooting

#2 @dd32
13 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.