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(); ?>
    			$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">&times;</span>
    				<div class="w3-container results">
    				<table width="100%" cellpadding="0" cellspacing="0" border="0">
    						<td class="header">Title</td>
    						<td class="header">Description</td>
    						<td class="header number">Ref #</td>
    						<td class="header">PDF</td>
    					<?php foreach( $posts as $p ): ?>
    							<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>
    					<?php endforeach; ?>
    			  <footer class="w3-container">
    		 <?php $id_increment++; ?>
    		<?php else : ?>
    		<h2 class="api-category"><?php echo $name; ?></h2>
    		<p class="api-name"><?php echo $value; ?></p>
    		<?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_postdata(); ?>