Support

Account

Home Forums Front-end Issues Extracting Relational data from repeater fields Reply To: Extracting Relational data from repeater fields

  • I would do something like this with the original code I posted

    
    <?php 
      if (get_field('event_session')) {
        while (has_sub_field('event_session')) {
          ?>
            <strong><?php the_sub_field('session_start'); ?></strong>
            <?php the_sub_field('session_title'); ?><br />
            <!-- Start of speaker list -->
            <div class="speaker_list">
              <?php
                $sessionspeakers = get_sub_field('session_speaker');
                if ($sessionspeakers) {
                  $count = 0;
                  echo 'Speaker';
                  if (count($sessionspeakers) > 1) {
                    echo 's';
                  }
                  echo ': ';
                  foreach ($sessionspeakers as $speaker) {
                    $count++;
                    $speakerlink = get_permalink($speaker->ID);
                    
                    $speakerurltext = get_post_meta($speaker->ID, 'speakerurltext', true);
    
                    // if 'speakerurltext' is an acf field you could use
                    // $speakerurltext = get_field('speakerurltext', $speaker->ID);
                    
                    if ($count > 1) {
                      echo ', ';
                    }
                    echo $speaker->post_title;
                  } // end foreach speakers
                } // end if speakers
              ?>
            </div>
          <?php 
        } // end while has_sub_field
      } // end if get_field
    ?>