Title: [Plugin: Posts 2 Posts] Setting direction for each_connected()
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Setting direction for each_connected()

 *  Resolved [dlukez](https://wordpress.org/support/users/dlukez/)
 * (@dlukez)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-setting-direction-for-each_connected/)
 * Hi scribu,
 * I’ve been learning your plugin the last few days. It seems to me that indeterminate
   connections with reciprocal => false may require a need to set the direction 
   when using each_connected(), because find_direction() will default it to ‘from’.
   I modified the function and got it to work for my intended purpose: [http://pastebin.com/3MkPWn2n](http://pastebin.com/3MkPWn2n)
   
   The changes I made are at lines 1, 10 and 20.
 * I’m relatively new to WordPress plugin coding so let me know if I’m just using
   the plugin wrong. I understand that you can achieve the same thing using p2p_type()-
   >set_direction()->get_connected() calls but I’m guessing that’s less efficient
   and a little more complex to implement.
 * A case where this might be useful is covered in [http://wordpress.org/support/topic/plugin-posts-2-posts-hwo-to-make-grandfather-father-son](http://wordpress.org/support/topic/plugin-posts-2-posts-hwo-to-make-grandfather-father-son)
 * Btw, thanks heaps for this plugin, it’s been super helpful!
 * Cheers
 * [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)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-setting-direction-for-each_connected/#post-2743138)
 * The most readable way to set the direction is by using p2p_distribute_connected()
   directly:
 *     ```
       $connected = get_posts( array(
         'connected_items' => $wp_query->posts,
         'connected_type' => 'YOUR_CONNECTION_TYPE',
         'connected_direction' => 'to',
         'nopaging' => true,
         'suppress_filters' => false
       ) );
   
       p2p_distribute_connected( $wp_query->posts, $connected, 'connected' );
       ```
   
 * It’s just as efficient as using each_connected().
 *  Thread Starter [dlukez](https://wordpress.org/support/users/dlukez/)
 * (@dlukez)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-setting-direction-for-each_connected/#post-2743174)
 * ok, thanks!

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

The topic ‘[Plugin: Posts 2 Posts] Setting direction for each_connected()’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [dlukez](https://wordpress.org/support/users/dlukez/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-setting-direction-for-each_connected/#post-2743174)
 * Status: resolved