Support

Account

Forum Replies Created

  • Oh my goodness – you are wonderful! This works! And now I understand what needed to happen. Thank you so very much for all your help.

    I hope this might help someone in the future!

  • Actually, I’m trying to display the related posts on the single product page, not the single post. So if I were to put the code you referenced above on the content-single-product.php page, nothing prints.

    Just in case my original post isn’t clear, the admin Relationship field is set up to appear on the admin post page. This is where I select all products associated to that particular post. Then I’m trying to display the results on the content-single-product.php page for each product that is associated to the post.

    So far what its resulting in (using the code I included in my second post) is the post appears on every product page, not only for each selected product. And it sometimes appears more than once.

    Again, thanks for your help!

  • Hi ractoon!
    Thanks for responding to my issue. Thanks – I actually tried it that way as well, but it doesn’t yield any results, even though I have the product selected within the relationship block on the admin post page. And to confirm, yes, I’m using post object and the Relationship field type.

    I had a developer friend take a look and although he’s not able to help out with this at the moment, he thinks this is what needs to happen: It has to find the posts of the custom field, then find the id’s from those posts by querying the db. Then, it has to return an array of those fields to the single product template, and based on that array of Id’s, set up a WP Query for those posts.

    So this seems more complicated than I originally anticipated it being. If you have any further thoughts beyond this, I’m all ears. Thanks again for your willingness to respond to my issue! Much appreciated.

  • Hi – Is there anyone who could help?

  • 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>
    
Viewing 5 posts - 1 through 5 (of 5 total)