Support

Account

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(); ?>