Title: [Plugin: Posts 2 Posts] Using each_connected multiple times isn&#039;t working
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Using each_connected multiple times isn't working

 *  [boscoiscool](https://wordpress.org/support/users/boscoiscool/)
 * (@boscoiscool)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-each_connected-multiple-times-isnt-working/)
 * Hey,
 * First off, thanks a lot for the plug-in – seems perfect for what I’m trying to
   do.
 * I modified the Looping the Loop example ([https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop](https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop))
   for using each_connected multiple times.
 * I have 3 cpt – recipes, tips and chefs. For each recipe I’m trying to display
   information about the connected tips and chefs.
 * In the code below, the recipe title and tip title appear, but nothing appears
   for the chef posts. If I comment out the foreach & wp_reset_postdata() code for
   the tip posts, then the chef post data does appear. I’m totally stumped on this
   one so any help would be greatly appreciated!
 * The code is either [http://pastebin.com/yz7gfUVY](http://pastebin.com/yz7gfUVY)
   or below.
    ` <?php $my_query = new WP_Query( array( ‘post_type’ => ‘recipes’ ));
 *  p2p_type( ‘recipes_to_tips’ )->each_connected( $my_query, array(), ‘tips’ );
 *  p2p_type( ‘recipes_to_chefs’ )->each_connected( $my_query, array(), ‘chefs’ );
   ?
   >
 *  <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <p>The 
   Recipe</> <?php the_title(); ?>
 *  <?php
    // Display connected tip
 *  echo ‘<p>Tip:</p>’;
 *  foreach ( $post->tips as $post ) : setup_postdata( $post );
    the_title(); endforeach;
 *  wp_reset_postdata();
 *  // Display connected chef
    echo ‘<p>Chef:</p>’; foreach ( $post->chefs as $post):
   setup_postdata( $post ); the_title(); endforeach;
 *  wp_reset_postdata();
    ?>
 *  <?php endwhile; ?>
    `
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

The topic ‘[Plugin: Posts 2 Posts] Using each_connected multiple times isn't working’
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

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

 * 0 replies
 * 1 participant
 * Last reply from: [boscoiscool](https://wordpress.org/support/users/boscoiscool/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-each_connected-multiple-times-isnt-working/)
 * Status: not resolved