Home › Forums › Add-ons › Repeater Field › Get custom field values from relationship post object inside repeater › Reply To: Get custom field values from relationship post object inside repeater
I actually had the repeater loop code but just didn’t post it. I was able to solve it though! I needed a PHP increment bit of code to get it working. Here is the final code in case it helps anyone else:
<?php if( have_rows('api_properties') ): ?>
<?php $id_increment = 0; ?>
<?php while ( have_rows('api_properties') ) : the_row(); ?>
<li>
<?php
$name = get_sub_field('api_name');
$value = get_sub_field('api_value');
$posts = get_sub_field('api_references');
?>
<?php if( $posts ): ?>
<h3 class="api-category"><!-- Button trigger modal -->
<button onclick="document.getElementById('id1_<?php echo $id_increment; ?>').style.display='block'" class="w3-button"></button><?php echo $name; ?></h3>
<p class="api-name"><?php echo $value; ?></p>
<div id="id1_<?php echo $id_increment; ?>" class="w3-modal">
<div class="w3-modal-content">
<header class="w3-container w3-teal">
<span onclick="document.getElementById('id1_<?php echo $id_increment; ?>').style.display='none'"
class="w3-button w3-display-topright">×</span>
<h3>References</h3>
</header>
<div class="w3-container results">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="header">Title</td>
<td class="header">Description</td>
<td class="header number">Ref #</td>
<td class="header">PDF</td>
</tr>
<?php foreach( $posts as $p ): ?>
<tr>
<td><?php echo get_the_title( $p->ID ); ?></td>
<td><?php echo get_field('reference_description', $p->ID); ?></td>
<td class="number"><?php echo get_field('reference_number', $p->ID); ?></td>
<td><?php echo get_field('reference_pdf', $p->ID); ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<footer class="w3-container">
<p> </p>
</footer>
</div>
<?php $id_increment++; ?>
</div>
<?php else : ?>
<h2 class="api-category"><?php echo $name; ?></h2>
<p class="api-name"><?php echo $value; ?></p>
<?php endif; ?>
</li>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
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.