Home › Forums › Add-ons › Repeater Field › Getting The First Two Rows of a Repeater and Then Outputting a Nested Repeater › Reply To: Getting The First Two Rows of a Repeater and Then Outputting a Nested Repeater
Just typing it up here and formatting it helped me work it out in my head:
<?php if( have_rows('press_releases') ): ?>
<h2>Press Releases <span class="sprite icon"></span></h2>
<div>
<?php endif; ?>
<?php
$prRows = get_field('press_releases' ); // get all the rows
$first_row = $prRows[0]; // get the first row
$first_row_year = $first_row['year'];
$first_row_pr = $first_row['pr_posts'];
?>
<h3><?php echo $first_row_year; ?></h3>
<?php
if($first_row_pr)
{
foreach($first_row_pr as $pr)
{
echo '<h4><a href="#">' . $pr['heading'] . '</a></h4>';
echo '<p>' . $pr['date'] . '</p>';
}
}
?>
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.