Maybe this could get you started:
function get_loser( $winner_id ) {
global $post;
$tournament = get_connected_id( $winner_id, 'won_final' );
$loser = get_connected_id( $tournament['ID'], 'lost_final' );
return $loser;
}
function get_connected_id( $from_id, $connected_type ) {
global $post;
$result = array(
'ID' => null,
'post_title' => null,
);
if ( null === $from_id ) return $result;
$connected = get_posts( array(
'connected_type' => $connected_type,
'connected_items' => $from_id,
'nopaging' => true,
)
);
if ( ! empty( $connected ) ) :
$result['ID'] = $connected[0]->ID;
$result['post_title'] = $connected[0]->post_title;
endif;
return $result;
}
Edit:
If you want all the losing players from all the tournaments that a certain player won, then I suggest doing something like this:
function get_losers( $winner_id ) {
global $post;
// get all tournaments won
$tournaments = get_connected_id( $winner_id, 'won_final' );
// this is the resulting array, init it.
$all_losers = array();
// Go through all the tournaments and find the loser
foreach( $tournaments as $tournament ):
$losers = get_connected_id( $tournament->ID, 'lost_final' );
foreach( $losers as $loser ) :
// Here's a new loser, store the id and tournament id
$new_loser = array();
$new_loser['ID'] = $loser->ID;
// add more fields if you like
$new_loser['tournament_id'] = $tournament->ID;
$all_losers[] = $new_loser;
endforeach;
endforeach;
// We are done return the array of losers.
return $all_losers;
}
function get_connected_id( $from_id, $connected_type ) {
global $post;
$result = array(
'ID' => null,
'post_title' => null,
);
if ( null === $from_id ) return $result;
$connected = get_posts( array(
'connected_type' => $connected_type,
'connected_items' => $from_id,
'nopaging' => true,
)
);
return $connected;
}