Home › Forums › General Issues › Relationship field in Woocommerce product loop › Reply To: Relationship field in Woocommerce product loop
Never mind, after posting the question I figured it out and it actually wasn’t difficult at all. See here below:
<ul class="products">
<?php
$ids = get_field('pp_relation', 'option', false, false);
$args = array(
'post_type' => 'product',
'post__in' => $ids,
'posts_per_page' => 4,
'orderby' => 'rand'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
do_action( 'iclicks_related_products_loop' );
echo '</div>';
endwhile;
}
wp_reset_postdata();
?>
</ul><!--/.products-->
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!
✨ You can now install ACF PRO with Composer, eliminating the need for third-party installers. Get the details and instructions here. https://t.co/ebEfp60Pwj
— Advanced Custom Fields (@wp_acf) February 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.