Home › Forums › General Issues › Post type = product per single product › Reply To: Post type = product per single product
Basically, you would delete the custom query and it’s associated loop and you would only need the code that starts with
$post_objects = get_field('featured_products');
and the loop associated with this field.
This would show posts associated with the current product.
You would keep this, but it may need some adjustments
$post_objects = get_field('featured_products');
if( $post_objects ): ?>
<div>
<h1>You may also like</h1>
<?php foreach( $post_objects as $post_object): ?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_object->ID ), 'single-post-thumbnail' ); ?>
<div class="single-feature">
<a href="<?php echo get_the_permalink($post_object->ID); ?>" class="img-feature">
<img src="<?php echo $image[0];?>">
</a>
<div class="product-title-price">
<a href="<?php echo get_the_permalink($post_object->ID); ?>">
<h3><?php echo get_the_title($post_object->ID); ?></h3>
</a>
<?php echo $price; ?>
</div>
</div>
</div>
<?php endforeach;
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.