Home › Forums › General Issues › Relationship Field in WP_Query › Reply To: Relationship Field in WP_Query
see my notes in comments. I’m not sure if this will cause the problem your having or not.
if ( $subservice->have_posts() ) : ?> <?php while ( $subservice->have_posts() ) : $subservice->the_post(); $count++?> <section class="pp-section" id="section<?php echo $count; ?>"><!-- no end tag --> <div class="fadearound"><!-- no end tag --> <div class="bgfadearound loading" style="background-image: url('<?php bloginfo('stylesheet_directory'); ?>/assets/img/bg_01.jpg');"></div> <div class="container-right"><!-- no end tag --> <?php $related_posts = get_field('reference_1'); if( $related_posts ): // no endif ?> <ul> <?php foreach( $related_posts as $p ): // variable must NOT be called $post (IMPORTANT) ?> <li> <a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a> <span>Custom field from $post: <?php the_field('author', $p->ID); ?></span> </li> <?php endforeach; ?> </ul> <?php endwhile; ?> <?php endif; wp_reset_query(); ?>
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.