I have pages containing a relationship field to a custom post type (properties). On each property I have a custom gallery field. I’m trying to figure out on the front end, how to get the get the gallery from within the related post. Here’s my code attempt with a chunk I know is missing – but don’t know what to put in there. `<?php
$locations = get_field(‘property_selection’); // this just returns the id of the property post
$gallery = get_field(‘property_gallery’);
if( $locations ): ?>
<?php endif; ?>
Never mind I managed to resolve this – here’s my solution if anyone is looking for similar:
<?php
$posts = get_field('property_selection');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<?php $gallery = get_field('property_gallery', $p->ID); ?>
<li><?php echo get_the_title( $p->ID ); ?></li>
<?php if($gallery) : foreach( $gallery as $item ): // variable must NOT be called $post (IMPORTANT) ?>
<li><?php echo $item['url']; ?> </li>
<?php endforeach; endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>