I've used the second-last example showed here: https://github.com/scribu/wp-posts-to-posts/wiki/each_connected
The only difference is that I've put the_title after echoing the connected posts. So my code is:
<?php
$my_query = new WP_Query( array(
'post_type' => 'movie'
) );
p2p_type( 'movies_to_actors' )->each_connected( $my_query, array(), 'actors' );
p2p_type( 'movies_to_locations' )->each_connected( $my_query, array(), 'locations' );
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<?php
// Display connected actors
echo '<p>Actors:</p>';
foreach ( $post->actors as $post ) : setup_postdata( $post );
the_title();
...
endforeach;
wp_reset_postdata();
// Display connected locations
echo '<p>Filming locations:</p>';
foreach ( $post->locations as $post ) : setup_postdata( $post );
the_title();
...
endforeach;
wp_reset_postdata();
?>
<?php the_title(); ?>
<?php endwhile; ?>
The problem is that all the posts show me the title of the first post:
Actors: actors of post title n.1
Locations: locations of post title n.1
TITLE n.1
Actors: actors of post title n.2
Locations: locations of post title n.2
TITLE n.1 <<<--- WRONG!!!