Make WordPress Core

Opened 20 years ago

Closed 20 years ago

Last modified 19 years ago

#1518 closed defect (bug) (fixed)

Determine if you are currently in "the loop" [PATCH]

Reported by: markjaquith's profile markjaquith Owned by: markjaquith's profile markjaquith
Milestone: Priority: normal
Severity: normal Version: 1.6
Component: Administration Keywords: bg|dev-feedback bg|2nd-opinion bg|has-patch
Focuses: Cc:

Description (last modified by markjaquith)

A lot of functions need to behave differently inside the loop as opposed to outside of the loop. These patches create the function in_loop() which returns true or false, based on whether or not you are currently in the loop.

A new var for $wp_query has been created: $in_loop

With each $this->the_post() call, $this->in_loop is set as true.

When the loop is over, and $this->have_posts() would normally just return false, $this->in_loop is set as false, the posts are rewinded, and the global $post variable is set $post = "";

This addresses part of #977

This function could also be used internally to protect functions that must be used inside the loop from being used outside of it (or at least providing an elegant error message so people know what the problem is).

Patch is against latest 1.6 SVN

Attachments (2)

classes.php.diff (949 bytes) - added by markjaquith 20 years ago.
1.6 SVN patch
functions.php.diff (356 bytes) - added by markjaquith 20 years ago.
1.6 SVN patch

Download all attachments as: .zip

Change History (6)

#1 @markjaquith
20 years ago

  • Description modified (diff)
  • Status changed from new to assigned

#2 @markjaquith
20 years ago

  • Description modified (diff)

@markjaquith
20 years ago

1.6 SVN patch

@markjaquith
20 years ago

1.6 SVN patch

#3 @ryan
20 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [2716]) in_the_loop() Props: Mark Jaquith fixes #1518

#4 @(none)
19 years ago

  • Milestone 2.0 deleted

Milestone 2.0 deleted

Note: See TracTickets for help on using tickets.