Support

Account

Home Forums Add-ons Repeater Field Creating a table from ACF repeater data

Unread

Creating a table from ACF repeater data

  • If you’re looking to use an ACF repeater to create an HTML table, here’s how I do it. The ACF function get_field_objects() is used in the post or page template in this case. Dump it out to see what’s in there.

    
    <?php $table = get_field_objects(); ?>
    <table class="table">
    	<thead>
    		<tr>
    			<th>First</th>
    			<th>Last</th>
    			<th>Phone</th>
    			<th>Email</th>
    			<th>Address</th>
    			<th>Joined</th>
    		</tr>
    	</thead>
    	<tbody>
    		<?php foreach ($table['directory_table']['value'] as $row) : ?>
    			<tr>
    				<td><?= $row['first'] ?></td>
    				<td><?= $row['last'] ?></td>
    				<td><?= $row['phone'] ?></td>
    				<td><?= $row['email'] ?></td>
    				<td><?= $row['address'] ?></td>
    				<td><?= $row['joined'] ?></td>
    			</tr>
    		<?php endforeach ?>
    	</tbody>
    </table>
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.