Home › Forums › General Issues › Loading a field with a Relationship field within a Flex Content Field › Reply To: Loading a field with a Relationship field within a Flex Content Field
Your remark got me thinking though, Elliot. And now I found the simple solution: rename the post object! The solution:
<?php // If selection is made, load selection of customers
$customers = get_sub_field('customers-select');
if( $customers ): ?>
<?php foreach( $customers as $customer): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($customer); ?>
<?php $post_id = $customer->ID; ?>
<?php $thumbid = get_post_thumbnail_id($post_id); ?>
<?php $img = wp_get_attachment_image_src( $thumbid, 'medium' ); ?>
<?php $logo = $img[0]; ?>
<?php $customer_url = get_field('customer-url', $post_id); ?>
<li class="l-fifth customer">
<a href="<?php echo $customer_url ?>" role="img" alt="<?php the_title(); ?>" style="background-image:url(<?php echo $logo ?>);"></a>
</li>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif;?>
Thanks & sorry for the waste of time, I should’ve known since I already used this method quite a lot of times.
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.