• Resolved aaron@rossano.com.au

    (@aaronrossanocomau)


    hi, i’ve created a wp_query to get two custom post types. post_type1 and post_type2.
    both are connected to post_type3. when i set my relationship on the query, the second relationship overrides the first one and erases the results, that forces me to use a different name for the results and having to duplicate code further when looping within the relationship.

    wp_query: ‘post_type’ => array(‘post_type1’, ‘post_type2’),..

    p2p_type( ‘post_type1_to_post_type3’ )->each_connected( $my_query, array(), ‘post3’ );
    p2p_type( ‘post_type2_to_post_type3’ )->each_connected( $my_query, array(), ‘post3’ );

    am i doing something wrong, or is this a bug?

    http://wordpress.org/extend/plugins/posts-to-posts/

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

    (@scribu)

    That’s an interesting edge case, but having each_connected() automatically merge the results doesn’t seem like the correct behaviour to me.

    And there’s nothing preventing you from merging the two lists yourself:

    p2p_type( 'post_type1_to_post_type3' )->each_connected( $my_query, array(), 'foo' );
    p2p_type( 'post_type2_to_post_type3' )->each_connected( $my_query, array(), 'bar' );
    
    foreach ( $my_query->posts as $post ) {
      $post->post3 = array_merge( $post->foo, $post->bar );
    }
    Thread Starter aaron@rossano.com.au

    (@aaronrossanocomau)

    that’s not a bad idea to set the array manually.
    ideally i think it should do it automatically so that i wouldn’t have to worry about losing data while using different post types.
    thanks so much for the quick reply!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Posts 2 Posts] query with multiple post types and same relationship overrides results’ is closed to new replies.