Multiple Nested Loops?
-
I have been struggling for days trying to get this to work, but I can’t get it right. I am trying create a spot to show a random featured artist every time the page is loaded.
In this spot, I created a loop to pull a random post within the “artist” category, along with the thumbnail, name and custom fields. I got this to work just like I wanted.
However, I also want to add a row of video thumbnails from the videos category, using the current loop to get the name from the video tags. Below that, I want a row of photos from the photos category, which also have the artist name in the tag.
I can get each function to work as it should…but I can’t get them to all work together at once. The first and second loop work, but the third is getting it’s info from the second loop instead of the first, like the second loop is still open. I’m still learning WP, so my guess is I’m using loops and queries the wrong way ??
This is essentially what I’m trying to do:
[first query to get random artist]
Featured Artist:
{artist thumb} {Artist Name (post title)}
{custom field in post}Videos featuring {Artist Name}
[second query to get videos]
{video post thumb} {video post thumb} {video post thumb}
[end video query]Photos featuring {Artist Name}
[third query to get photos]
{photo post thumb} {photo post thumb} {photo post thumb}
[end photo query]
[end artist query]This is the mess I have now. It keeps re-looping and the 3rd photo loop is reading from the 2nd loop:
[code moderated - please follow the forum guidelines for posting code]
Any help would be greatly appreciated. I'm starting to pullout my hair figuring out WP loops!
~ Nicole
- The topic ‘Multiple Nested Loops?’ is closed to new replies.