Home › Forums › Add-ons › Repeater Field › Problem with 1 element being ommited in the list
Hi guys,
I am trying to build simple system that lets assign pdfs to a page and then display choosen group of these pdf files in the widget.
Widget displays files from certain year, based on provided year in the widget field.
The problem I have is that it almost works. For some reason first file is being ommited. Can you please check my code and see what’s wrong ?
<ul id="pobieranieBoxWrapp">
<?php if(get_field('rok_element_pobieranie', 'widget_' . $args['widget_id'])):
// Display and set year to a constant.
$yearSet = get_field('rok_element_pobieranie', 'widget_' . $args['widget_id']) ?>
<h4>
<?php echo $yearSet; ?><span> årgang</span>
</h4>
<?php endif; ?>
<?php
// We set page with pdfs
if(get_field('skad_pobrac_pliki', 'widget_' . $args['widget_id'])): ?>
<?php $stronaPdfy = get_field('skad_pobrac_pliki', 'widget_' . $args['widget_id']); ?>
<?php endif; ?>
<?php
// check if the repeater field has rows of data
if( have_rows('newsletter_year_section', $stronaPdfy)): ?>
<?php
// Loop all files from the page
while ( have_rows('newsletter_year_section', $stronaPdfy)) : the_row();
// Condition to limit listed files only to selected year
if (get_sub_field('newsletter_year') == $yearSet):
?>
<?php if( have_rows('newsletter_files_section', $stronaPdfy) ): the_row(); ?>
<?php while( have_rows('newsletter_files_section', $stronaPdfy) ): the_row(); ?>
<?php if(get_sub_field('newsletter_pdf_file')):
//Set the pdf file
$file = get_sub_field('newsletter_pdf_file');
$fileTitle = $file['title'];
$fileUrl = $file['url'];
?>
<li>
<a target="_blank" rel="nofollow" href="<?php echo $fileUrl; ?>">
<?php echo $shortName = str_replace('_',' ', $fileTitle); ?>
</a>
</li>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<?php // empty ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<li>No files yet</li>
<?php endif; ?>
</ul>
Hi @mastafu
Could you please make sure that the field returns the data correctly? Could you please debug it like this:
echo <pre>;
var_dump( get_field('newsletter_files_section', $stronaPdfy) );
echo </pre>;
Also, could you please share the JSON or XML export file of your field group so I can test it out on my installation?
Thanks 🙂
Looks like the problem lies in this.
This:
<?php if( have_rows('newsletter_files_section', $stronaPdfy) ): the_row(); ?>
<?php while( have_rows('newsletter_files_section', $stronaPdfy) ): the_row(); ?>
Should be like this:
<?php if( have_rows('newsletter_files_section') ): ?>
<?php while( have_rows('newsletter_files_section') ): the_row(); ?>
The topic ‘Problem with 1 element being ommited in the list’ 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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.