Home › Forums › Add-ons › Repeater Field › Help with Creating a Table Using Nested Repeaters
Hey friends!
I am trying to use nested repeaters to output a table layout.
My final goal is to create a chronological list of service projects organized by decade. So each decade contains a list of rows, for each year in that decade. The year rows have 4 fields: year, project, donation, notes.
Here is what I have set up:
1) I have a field group called “Past Grand Service Projects”
2) I have a repeater field called “Grand Service” (grand_service)
3) Nested inside this repeater field is: 1) a text field I want to use for the decade label (decade) and 2) another repeater that will create the rows for the years within the decade.
I have everything set up correctly in ACF. I can click to add new decades or new years on the back end.
My issue is that I don’t know how to properly display it on the front end.
Below is the code I am trying, but it is not working and I would love to get this table layout outputted on the Past Grand Service page of my site.
if( have_rows('grand_service'):
while ( have_rows('grand_service') ) : the_row(); ?>
<h2><?php the_sub_field('decade'); ?></h2>
<?php if ( have_rows('year') ): ?>
<table>
<thead>
<tr>
<td>Year</td>
<td>Project</td>
<td>Donation</td>
<td>Notes</td>
</tr>
</thead>
<?php while ( have_rows('year') ) : the_row(); ?>
<tr>
<td><?php the_sub_field('pgsp_year'); ?></td>
<td><?php the_sub_field('pgsp_project'); ?></td>
<td><?php the_sub_field('pgsp_donation'); ?></td>
<td><?php the_sub_field('pgsp_notes'); ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Something is wrong and I don’t know what. I may need to have the get_sub_field in there, but I am just not sure.
Any help would be hugely appreciated! I have attached a screenshot of my ACF setup.
Thanks
From what I can see, you have this set up exactly how it should be. About the only thing I can ask before I try to duplicate this is:
Is this on a post page or an options page?
John,
Ok, thanks for getting back to me. I have resolved the issue above, but I have a new issue: I have a repeater that has gone haywire and is repeating into infinity!!!
Here is the page:
http://demo.bodiequirkdesign.com/all-about-ca-rainbow/assemblies-of-ca/
Here is the page template:
<?php
add_action( 'genesis_entry_content', 'rainbow_assemblies_of_ca' );
function rainbow_assemblies_of_ca() {
if ( have_rows('assemblies_of_ca') ):
while ( have_rows('assemblies_of_ca') ) : the_row(); ?>
<h2 class="decade-title"><?php the_sub_field('region_of_ca'); ?><h2>
<?php if ( have_rows('assemblies_of_ca') ): ?>
<table>
<thead>
<tr class="assemblies-row">
<td>City</td>
<td>Address</td>
<td>Meeting Times</td>
<td>Contact Person</td>
</tr>
</thead>
<?php while ( have_rows('assembly_info') ) : the_row(); ?>
<tr class="assemblies-row">
<td><?php the_sub_field('assembly_city'); ?></td>
<td><?php the_sub_field('assembly_address'); ?></td>
<td><?php the_sub_field('assembly_meeting_times'); ?></td>
<td><?php the_sub_field('assembly_contact_person'); ?></td>
</tr>
<?php endwhile; // end assemblies info ?>
</table>
<?php endif; // end assembly_info ?>
<?php endwhile; // end assemblies_of_ca ?>
<?php endif; // end assemblies_of_ca
} // End rainbow_assemblies_of_ca();
genesis(); // Initialize Genesis
// End of File
Can you see what is causing the repeater to never stop? I must be missing something simple, but I can’t see it.
Thanks!
if ( have_rows('assemblies_of_ca') ):
while ( have_rows('assemblies_of_ca') ) : the_row(); ?>
<?php if ( have_rows('assemblies_of_ca') ): ?>
<?php while ( have_rows('assembly_info') ) :
I think that second if should probably be
if ( have_rows('assembly_info') ):
Yup, that was it! Thanks again. This plugin is amazing. Can’t wait to learn more about how to use it.
The topic ‘Help with Creating a Table Using Nested Repeaters’ is closed to new replies.
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.