I have 3 custom post types:
Transaction
Producer
Location
Transaction contains a relationship field filtered by Producer, and Producer contains a relationship field filtered by Location.
Transaction => Producer => Location
On the Single Transaction page, I would like to output values from all 3 custom post types.
I’m having no problem outputting values from the the Producer because of the direct relationship to the Transaction, but since the Location is a relationship to the Producer, I’m having trouble getting those values to come through.
Currently, I’m trying a nested foreach loop, with the internal loop referencing a reverse query, but the value outputs incorrectly. Am I going about this the right way? Or is there a better way to access those values?
Here is my code below on the Single Transaction Page:
<h4>Transaction Contacts</h4>
<?php
$producers = get_field('transaction_contacts');
if($producers):
?>
<ul class="list-unstyled">
<?php foreach( $producers as $p) : ?>
<?php
$office_location = get_posts(array(
'post_type' => 'producer',
'meta_query' => array(
'key' => 'office_location',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
));
?>
<li>
<p><?php echo get_the_title($p->ID); ?></p>
<?php foreach( $office_location as $o) : ?>
<p><?php echo get_the_title($o->ID); ?></p>
<?php endforeach; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Thanks in advance for any help. I apologize if this has been answered before, I had trouble finding anything relating to it.