I’ve finally figured it out. This is what I used to be able to show my related posts on WooCommerce product pages:
<?php $vendorposts = get_field('related_posts'); if( $vendorposts ): ?> <div class="latest_post_holder boxes three_columns two_rows"> <ul> <?php foreach( $vendorposts as $post): // variable must be called $post (IMPORTANT) ?> <?php setup_postdata($post); ?> <li> <?php if ( has_post_thumbnail( $rp->ID ) ) : ?> <?php echo get_the_post_thumbnail( $rp->ID, 'regular-posts' ); ?> <?php else : ?> <img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" /> <?php endif; ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; ?> </ul> </div> <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> <?php endif; ?>
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.