#1518 closed defect (bug) (fixed)
Determine if you are currently in "the loop" [PATCH]
Reported by: |
|
Owned by: |
|
---|---|---|---|
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 )
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
1.6 SVN patch