Support

Account

Home Forums Front-end Issues Displaying Sibling ACF Fields Reply To: Displaying Sibling ACF Fields

  • After doing some more reading I found that I can pass a pageID to have_rows and retrieve fields that way, so I thought I could maybe retrieve an array of all the siblings of a page and just loop through them. However, I can’t find the appropriate way to do this. Am I going about this right way? Is there a better way to implement to this?

    
    <?php
    $pageId = array-of-sibling-ids.
    ?>
    <?php 
     foreach ($pageId as $sibling) {
        if( have_rows('single_project_hero', $sibling) ): 
    
        while( have_rows('single_project_hero', $sibling) ): the_row();  
        $image   = get_sub_field('single_project_hero_image');
        $heading = get_sub_field('single_project_hero_headline');
        $teaser = get_sub_field('single_project_hero_teaser');
      ?>
      <?php if ($image): ?>
        <div class="singleProject__hero">
          <img src="<?php echo $image ?>"/> 
          <div class="singleProject__heroCopy centered-heading">
            <h2 class="title"><?php echo $heading ?></h2> 
            <p class="copy"><?php echo $teaser ?></p>
          </div>
        </div>
      <?php endif; ?>
    
      <?php endwhile; ?>
      <?php endif; ?>