• (I THINK that’s the version of WordPress I’m using– not sure).

    To make a long story slightly less long: I have created a second loop on single.php of twentyeleven to display all posts underneath the single post that the user may navigate to…

    It worked, but I am confused… Every resource (including the codex) suggests either resetting the loop’s counter with?putting rewind_posts(); before the start of the second loop, and/or putting either wp_reset_postdata(); or wp_reset_query();
    after the 1st endwhile;, and also putting both loops into their own variables ($myloop = new WP_Query for example)…

    During trying to implement a second loop on single.php I have discovered that out of all the above, the only thing that was needed was for the second loop to be stored in its own variable (code worked fine regardless of how i chose to reset the loop counter…I even tried it without resetting the counter and it STILL WORKED).

    My question about the above is: why is it still working?..kinda ironic, but i must be doing something wrong or misunderstanding something if it still works considering my deliberate deviations

    [mod: moved to ‘Miscellaneous’]

Viewing 1 replies (of 1 total)
  • It’s going to depend upon the individual situation. For example, someone might want to display pagination links based on the primary Loop after the secondary Loop. In that situation, they may have very unpredictable pagination links unless they reset after the secondary query.

    The Codex has to try and cover as many different scenarios as concisely as possible. The various resources recommend resetting the queries because it won’t cause a problem and could resolve an issue that is otherwise causing you to tear your own hair out. So, whilst it should be considered Best Practice, if the loop-sans-reset works for you, that’s just fine. ??

    HTH

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple loops’ is closed to new replies.