Ah, that makes sense. So this is rather a reverse relationship query. In that case your friend was correct, but it can be done in a single query:
<?php $related_posts = get_posts(array( 'post_type' => 'post', 'numposts' => -1, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'related_products', 'value' => '"' . get_the_ID() . '"', 'compare' => 'LIKE' ), ) )); ?> <?php if ( $related_posts ): ?> <ul class="medium-block-grid-5 blog-posts"> <?php foreach( $related_posts as $rp ): ?> <li class="post"> <a href="<?php echo get_permalink( $rp->ID ); ?>" title="<?php the_title_attribute( array( 'post' => $rp->ID ) ); ?>" ><span class="featured-title"><h3><?php echo get_the_title( $rp->ID ); ?></h3></span></a> <?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; ?> </li> <?php endforeach; ?> </ul> <?php 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!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.— Advanced Custom Fields (@wp_acf) January 6, 2023
© 2023 Advanced Custom Fields.