Home › Forums › General Issues › Relationship field in Woocommerce product loop › Reply To: Relationship field in Woocommerce product loop
The solution with ACF relation field – post type ‘Products’ selected, and is set to ‘Post object’
<ul class=”slider sp-interested-too-carousel product-carousel-boxes”>
<?php
$theProducts = get_field(‘sp_interested_too_products_choosing’);
$theProductsIds = array();
foreach ($theProducts as $product) {
$theProductsIds[] = $product->ID;
}
$args = array(
‘post_type’ => ‘product’,
‘post__in’ => $theProductsIds,
‘posts_per_page’ => 10,
‘orderby’ => ‘rand’
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
endwhile;
} else {
echo __( ‘No products found’ );
}
wp_reset_postdata();
?>
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.