Home Forums Front-end Issues Display Relationship Posts in Grid Reply To: Display Relationship Posts in Grid

  • I’ve finally figured it out. This is what I used to be able to show my related posts on WooCommerce product pages:

    $vendorposts = get_field('related_posts');
    if( $vendorposts ): ?>
        <div class="latest_post_holder boxes three_columns two_rows">
        <?php foreach( $vendorposts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
                        <?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>
        <?php endforeach; ?>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>