Home › Forums › Front-end Issues › Extracting Relational data from repeater fields › Reply To: Extracting Relational data from repeater fields
You can just change the option of that field to
Select multiple values?
to Yes
The difference is that if that is set to No, then you’ll get a single post object, but if it’s set to Yes then you’ll get an array of post objects, and the loop for displaying them would be different.
The following would replace the field loop if you set the field to allow multiple selections.
<?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 'Speakers: ';
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
?>
If you’re only allowing one selection then you would not need a loop for the speakers.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.