• Resolved dlukez

    (@dlukez)


    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
    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://ww.wp.xz.cn/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://ww.wp.xz.cn/extend/plugins/posts-to-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author scribu

    (@scribu)

    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

    (@dlukez)

    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.