[Plugin: Posts 2 Posts] reciprocal connections

I’m using Posts 2 Posts plugin. I’ve got 2 custom types : movies and actors. I created a movie => actor connection so that for each movie I can see which actors play in.

But as far as I understand, in order to find out all the movies a particular actor has played in, you must create an actor => movie connection AS WELL.

Read More

So if create a The Dark Knight => Christian Bale connection, I MUST create a Christian Bale => The Dark Knight as well. Because otherwise I won’t be able to know that Christian Bale played in that movie based on a “Christian Bale” search.

Is that correct ? If so, is there any way to make it less burdensome ?

Related posts

Leave a Reply

2 comments

  1. To see connections on both edit screens, set reciprocal to true, but note this is for the UI only, it doesn’t affect connections otherwise.

    function my_connection_types() {
        if ( !function_exists( 'p2p_register_connection_type' ) )
            return;
    
        p2p_register_connection_type( array( 
            'from' => 'movies',
            'to' => 'actors',
            'reciprocal' => true
        ) );
    }
    add_action( 'init', 'my_connection_types', 100 );
    
  2. No, you shouldn’t need one each way.

    You can query on either direction of the one connection, so something like this would get you all actors in Dark Knight:

    $actors = new WP_Query( array(
      'post_type' => 'actors',
      'connected_from' => $dark_knights_post_id,
    ));
    

    And this would get you all movies that Christian Bale has been in:

    $bale_movies = new WP_Query( array(
      'post_type' => 'movies',
      'connected_to' => $christian_bales_post_id,
    ));
    

    You can read more on the plugin’s documentation page.