Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#10048 closed defect (bug) (invalid)

Condition tag is_home() returns wrong result if it is called after query_posts()

Reported by: kamiyeye's profile kamiyeye Owned by:
Milestone: Priority: high
Severity: major Version: 2.8
Component: General Keywords:
Focuses: Cc:

Description

Pre-requisites:

Prepare a test-purpose php script, say:

$home = is_home() ? 'you are home': 'you are NOT home';
echo '<script type="text/javascript">alert("'.$home.'")</script>';

query_posts('showposts=1');
			
$home = is_home() ? 'you are home': 'you are NOT home';
echo '<script type="text/javascript">alert("'.$home.'")</script>';

Repro Steps

  1. Insert the test-purpose php script into a template php file, say single.php, then save.
  2. Visit any single post page in the blog

Expected Result

A message box pops up twice with the same text on it: you are NOT home

Actual Result

A message box pops up twice with differen texts on it, first is "you are NOT home", second is "you are home"

Change History (2)

#1 @dd32
15 years ago

Yes, Using query_posts() overrides the current global loop.

AFAIK you should use a custom loop (ie. new WP_Query) instead if you wish to retain THE loop whilst having your own loop.

See also: #9854

#2 @ryan
15 years ago

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

wp_reset_query() is also handy.

Note: See TracTickets for help on using tickets.