Support

Account

Home Forums Add-ons Repeater Field Problem with 1 element being ommited in the list

Solved

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 🙂

  • Returns Null, weird.
    Will send you all files via email.

  • 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(); ?>
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.