Home › Forums › Front-end Issues › Relating posts with Woocommerce products › Reply To: Relating posts with Woocommerce products
I’ve been working on this further, still not working, but wanted to put my updates here in case anyone sees anything obvious. What happens with this is that it displays the associated post, but each instance of it appears on the page. So if I select the same post for two products, on both of those product pages it appears twice. I feel like I’m close, but can’t figure it out.
Thanks for your help.
<ul class="medium-block-grid-5 blog-posts">
<?php
$args = array( 'posts_per_page' => -1 );
$fposts = get_posts( $args );
foreach ( $fposts as $post ) : ?>
<?php setup_postdata($post); ?>
<?php $product = get_field('related_products'); if( $product ): ?>
<?php foreach( $product as $p ): ?>
<li class="post">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><span class="featured-title"><h3><?php the_title(); ?></h3></span></a>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('regular-posts'); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; wp_reset_postdata();?>
</ul>
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βre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.