Ready to get started?Download WordPress


Custom loops (3 posts)

  1. Neil Nand
    Posted 9 months ago #


    This might seem like a bit of a strange question but there's something that I'm finding really hard to understand so was hoping someone could clear it up for me.

    If I create a separate instance of the WP_Query object for a custom loop to work along side my main loop, lets say this custom loop is the first thing on the page, I then need to reset the loop so because my custom loop will have affected it?

    Is that correct? The thing I'm finding hard to understand is that if I've created a separate instance of the WP_Query object then how is this affecting the main default page loop? Is it because the $post variable gets altered?

    Thanks very much for any help, I've been searching for ages on the Internet for an answer and non of the ones I've found (of which there are quite a few) are really clearing this up for me.

  2. keesiemeijer
    Posted 8 months ago #

    Use wp_reset_postdata() for a separate instance of the WP_Query object. It restores the global $post variable to the current post in the main query.


  3. Neil Nand
    Posted 8 months ago #


    Thanks for the reply but I was looking for help understanding how the loop works and why separate instances of the WP_Query object interfere with the main loop.


You must log in to post.

About this Topic