Support

Account

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>