Title: [Plugin: Post2Post] Problem with multiple each_connected
Last modified: August 20, 2016

---

# [Plugin: Post2Post] Problem with multiple each_connected

 *  [ChrisLowrance](https://wordpress.org/support/users/chrislowrance/)
 * (@chrislowrance)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-post2post/)
 * Generally Post2Post is a life-saver, but today I’ve been stuck on the following:
 * I have a post type “Movie,” and I need to display a list of connected post type“
   Scene.” With each Scene, I need to display connected post types “Director” and“
   Performer.”
 * I’ve tried all of the methods on [https://github.com/scribu/wp-posts-to-posts/wiki/each_connected](https://github.com/scribu/wp-posts-to-posts/wiki/each_connected)
   and each presents a similar problem: It will return Scenes, and it will return
   the _first_ connected post type below that. The second will generate an error.
   For the preferred method (each_connected), the error is: **Invalid argument supplied
   for foreach()**… on the line of the second foreach() call. Doesn’t matter which
   is second.
 * Here’s my current code. I’ve tinkered with it all day, and even switched to the
   nested WP_Queries method (that gave me a “no direction(s) error… again, on the
   second query only).
 *     ```
       <?php
       // Find connected posts
       $scenes = new WP_Query( array(
         'connected_type' => 'movie_to_scene',
         'connected_items' => get_queried_object(),
         'nopaging' => true
       ) );
       p2p_type( 'performer_to_scene' )->each_connected( $scenes, array(), 'joy_performer' );
       p2p_type( 'director_to_scene' )->each_connected( $scenes, array(), 'joy_director' );
       if ( $scenes->have_posts() ) :
       while ( $scenes->have_posts() ) : $scenes->the_post(); ?>
       	  <div class="row-fluid">
       	  <div class="span3">
             </div>
             <div class="span9 entry-content">
              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
              <!-- scene info -->
              <?php
   
              foreach ( $post->joy_performer as $post ) : setup_postdata( $post );
       		the_title();
       	endforeach;
       	wp_reset_postdata();
   
              foreach ( $post->joy_director as $post ) : setup_postdata( $post );
       		the_title();
       	endforeach;
       	wp_reset_postdata();
              ?>
   
              <!-- /scene info -->
             </div>
   
           </div>
           <?php endwhile; wp_reset_postdata(); endif; ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [JVel](https://wordpress.org/support/users/jvel/)
 * (@jvel)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/plugin-post2post/#post-3374918)
 * I had same problem, maybe it’t somehow related to wp_reset_postdata?
 * I get it working with code like this, which uses reset only once:
    ` global $
   post; $joy_performer = $post->joy_performer; $joy_director = $post->joy_director;
   foreach ( $joy_performer as $post ) : setup_postdata( $post ); ... endforeach;
 *  foreach ( $joy_director as $post ) : setup_postdata( $post );
    ... endforeach;
   wp_reset_postdata();
 * (I know this thread is almost year old, but maybe someone finds this reply useful)

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Post2Post] Problem with multiple each_connected’ is closed to
new replies.

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [JVel](https://wordpress.org/support/users/jvel/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/plugin-post2post/#post-3374918)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
