Hi, I have a problem with a relationship field inside a repeater; I have two custom post types, PT1 and PT2 with PT1 related to PT2 with a relationship field inside a repeater. Now I need that inside a PT2 post page wordpress shows me the post title, a subfield, and two custom fields (wich I need for a php function) stored inside the PT1 for every PT1 post related to a PT2 post.
I’ve created this image to make it a little more clear.

Do you have any idea how I can achieve this? Thank you.
I’ve solved part of the problem with some wpdb queries; now I have to show the subfields wich are in the same row of the relationship field called by the query.
To be more clear:
global $wpdb;
$queries = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key LIKE 'key1_%_key2' AND meta_value LIKE '%" . get_the_ID() . "%'");
?>
<?php if( $queries ): ?>
<ul>
<?php foreach( $queries as $query ): ?>
<?php
$photo = get_field('_photo', $query->post_id);
?>
<li>
<a href="<?php echo get_permalink( $query->post_id ); ?>">
<img src="<?php echo $photo?>" width="65" />
<?php echo get_the_title( $query->post_id ); ?>
</a></li>
<?php endforeach; ?>
</ul>
<?php endif;
There is a way to know the index of the row of every selected field, or something that can output the other subfields in the same row automatically? Do you know how I can achieve this? Thank you.