Contents
Is there a WP query loop within a loop?
I’m using a couple of custom wp_query loops on my page, the first one retrieves news from a certain category then displays a small excerpt from it with the permalink. The second one is another wp_query that gets a custom post type with a few advanced custom fields.
How to make a loop within a loop?
The problem is I’d like another loop within the second one that gets 3 posts from the news section with a thumbnail (basically the opposite of the first loop, it’ll get all the other categories). After reading countless articles on the loop I can’t figure out how to make a ‘nested’ loop within my second loop.
How to save outer loop data in WordPress?
In the solution you first saved the outer loop’s data in another variable before the contents get lost. Then the loop works as it’s supposed to be (deleting all outer loop data).
How is Outer Loop related to Inner Loop?
Here when you called the inner loop, the postdata related to the outer loop was getting lost when the inner loop starts working. Then whatever function you use after the end of inner loop is still finding only the inner loop’s data. In the solution you first saved the outer loop’s data in another variable before the contents get lost.
What do you need to know about loop in WordPress?
The loop is the code you use to display the data that WordPress has fetched from the database based on your query arguments. As I’ve demonstrated, there are a few variations on the loop. A simple loop will just output all posts in the order you’ve specified in your query arguments (or by date in descending order by default).
When to use offset in WP _ query loop?
‘offset’ = ‘1’, used with the second query, skips the first post, ensuring it’s not repeated in the list below. As you can see from the code above, the loop is slightly different for each query.