In wordpress theme or plugin development a developer fall in a situation sometime where he needs to call 2 different loops in same page, For example a developer can be in need to call a loop to display posts in post area by latest posts, and in sidebar he want to call random posts from database. But when he run query that returns same things in both.
WordPress multiple loops can be taken by resetting query after its use. Means if you are using a loop set
<?php if(have_posts()): while(have_posts()): the_post();
endwhile; endif; ?>
As above loop extracting latest posts from database the number of posts are same which you setup in wordpress backend in settings>reading. Now you want to stop extracting latest posts and you want to extract random wordpress posts. Just put following code at the end of your above code this will reset the wordpress query object and you can query new posts on base of random posts.
That’s all to reset wordpress loop and run multiple loops in a page.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?