Title: Two nested loops- only one works
Last modified: August 20, 2016

---

# Two nested loops- only one works

 *  Resolved [kemie](https://wordpress.org/support/users/kemie/)
 * (@kemie)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/two-nested-loops-only-one-works/)
 * I’m a bit stumped.
    I have a CPT of event that has another CPT of sponsors connected
   to it
 * On the homepage, I want to show a list of events, and for each event I want to
   show the sponsors, but first the ones of category “platinum”, then “gold” etc.
 * So I have multiple nested queries, one for each category ( I know there’s probably
   better ways to do this, but I’m not really a programmer). The problem is only
   the first one works. The following ones always return
 * > Warning: Could not find direction(s). in /home/…/wp-content/plugins/posts-to-
   > posts/core/query-post.php on line 16
 * regardless of which one is first, only the first one works. I’ve tried explicitly
   setting ‘connected_direction’ => ‘any’. this removes the error, but still shows
   nothing.
 * This is my ugly code:
    [http://pastebin.com/dag3wi3b](http://pastebin.com/dag3wi3b)
 * Any clues will be appreciated
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [kemie](https://wordpress.org/support/users/kemie/)
 * (@kemie)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/two-nested-loops-only-one-works/#post-3445383)
 * Talking to myself here. Not sure what was wrong originally, but solved by instead
   using foreach:
 *     ```
       $platinum = get_posts( array(
       				'connected_type' => 'sponsors_to_event',
       				'connected_items' => $post,
       				'nopaging' => true,
       				'cat'=>18,
       			) );
   
       			foreach ( $platinum as $sponsor ) {
       				echo $sponsor->post_title;
       			};
       ```
   
 *  Thread Starter [kemie](https://wordpress.org/support/users/kemie/)
 * (@kemie)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/two-nested-loops-only-one-works/#post-3445489)
 * Spoke too soon. Now my THIRD loop is not working. I’m tearing my hair out here.
   Any clues?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Two nested loops- only one works’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [nested](https://wordpress.org/support/topic-tag/nested/)

 * 2 replies
 * 1 participant
 * Last reply from: [kemie](https://wordpress.org/support/users/kemie/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/two-nested-loops-only-one-works/#post-3445489)
 * Status: resolved