[wp-hackers] Resetting after multiple loops

Jeremy Clarke jer-wphackers at simianuprising.com
Mon Oct 27 14:33:53 GMT 2008

On Mon, Oct 27, 2008 at 9:23 AM, Otto <otto at ottodestruct.com> wrote:
> On Mon, Oct 27, 2008 at 4:25 AM, Nigel Dunn <nigel at redefine.co.uk> wrote:
> In other words, what in the heck are you doing AFTER your loop that
> requires those values in the first place? That's where the problem is.
> You shouldn't be doing whatever that is.

That's a pretty good point. If there is something in your main/alt
loops that you need to have for later don't depend on the fact that wp
doesn't completely destroy the loop variables after the loop ends.
While you are in the loop save that data somewhere so that you can
call it.

For example, on our site we run a pre-loop that just shows posts with
the 'feature' category, and in the process we add the id's of shown
posts to a global array so that when we show the normal posts we can
check and make sure they weren't already shown as features. It is much
more sustainable to store things in a place you set explicitly rather
than depending on their shadows that hang round in $post or whatever.

In my experience problems with globals like $cat, $page etc all come
down to using query_posts() or the *OLD* get_posts() somewhere in your
templates. Find those and kill them ASAP (or at least query_posts() ).

Jeremy Clarke | http://simianuprising.com
Code and Design | http://globalvoicesonline.org

More information about the wp-hackers mailing list