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; ?> <?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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw— Advanced Custom Fields (@wp_acf) June 5, 2023
© 2023 Advanced Custom Fields.