Home › Forums › General Issues › Relationship Gallery issue › Reply To: Relationship Gallery issue
Hey Elliot,
Sorry, I simplified that to make it easy to understand (but prob made it more confusing :B ). Here’s my full code:
<?php
$args = array ( 'post_type' => 'school-category');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div>
<?php
/* films is a realtionship ACF field */
$films = get_field('films');
if( $films ): ?>
<div class="image_data">
<?php foreach( $films as $post): ?>
<?php setup_postdata($post); ?>
<?php if ( get_field('running_time') ) :
the_field('running_time');
endif; ?>
<?php if ( get_field('images') ) :
$images = get_field('images'); ?>
<img src="<?php echo $images[0]['url']; ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
The issue is that the if (get_fields(‘images’)) returns a false, where as all over the rest of the site it returns true. I dumped all the post’s custom fields and could see that images was an empty array, where all the ACF fields returned their values.
Any ideas? Thanks Elliot!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.