Support

Account

Home Forums Add-ons Repeater Field repeater field not returning data

Solving

repeater field not returning data

  • I have two repeater fields, the second is duplicated from the first. The first one works fine, but the second one does not return any data.

    The php for the problematic repeater is as follows:

    <?php if ( have_rows('faq_column_2') ) : 
            while ( have_rows('faq_column_2') ) :
              the_row(); ?>
                <div class="faq_accordian">
                  <div class="title"><?php the_sub_field('question_col2'); ?></div>
                  <div class="copy"><?php the_sub_field('answer_col2'); ?></div>
                </div>
            <?php endwhile;
              else :
                echo ('no rows found'); 
              endif; ?>

    My field names match up as shown in this screenshot:
    acf repeater screenshot

    I have tried rewriting the code (rather than copy/paste), I deleted the ACF plugin, uploaded the latest version, edited the sub fields to have a different name, and no luck. Then I deleted the repeater field, added a new one with all new names, still no luck.

    I tried a var_dump as described in this support thread, and it returns all my data successfully.

    The repeater, however, always returns “no rows found”. Very strange. Any ideas?

  • I’m not sure what you mean by

    I have two repeater fields, the second is duplicated from the first. The first one works fine, but the second one does not return any data.

    It would probably help to see the code from both repeaters, I don’t see anything wrong with the code you posted

  • Here’s my whole section of code. The two repeaters are pretty much the same. I just refactored the second one a little and added the ‘no rows found’ echo.

    <section id="faq" class="white section6">
    <div class="container">
      <div class="row">
        <div class="col-md-12" style="padding:70px 15px 0;">
          <h3 align="center">FAQ</h3>
        </div>
      </div>
      <div class="row table-row">
        <div class="col-sm-6" style="padding:15px 15px 75px;">
          <?php if ( have_rows('faq') ) : ?>
          <?php while ( have_rows('faq') ) :
          the_row();  ?>
          <div class="faq-accordian">
            <div class="title"><?php the_sub_field('question'); ?></div>
            <div class="copy"><?php the_sub_field('answer'); ?></div>
          </div>
          <?php endwhile; ?>
          <?php endif; ?>
        </div>
        <div class="col-sm-6" style="padding:15px 15px 75px;">
          <?php if ( have_rows('faq_column_2') ) :
          while ( have_rows('faq_column_2') ) :
          the_row(); ?>
          <div class="faq_accordian">
            <div class="title"><?php the_sub_field('question_col2'); ?></div>
            <div class="copy"><?php the_sub_field('answer_col2'); ?></div>
          </div>
          <?php endwhile;
          else :
          echo ('no rows found');
          endif; ?>
        </div>
      </div>
    </div>
    </section>
  • I really don’t see anything wrong there, I’m kinda stumped.

    Just out of curiosity, what happens if you put column 2 before column 1?

  • Really strange.
    Here’s the code to begin with:
    screen1b
    The result:
    screen1a

    Now if I swap the repeaters:
    screen2b
    The result:
    screen2a
    *Note that the faqs in the second repeater also appear in the first repeater. This is not because the two repeaters are showing up together in the first example. It’s because that is the way the data is entered into the admin. Sorry to be confusing.

  • Update. Had someone else pull my code to their local copy, and it works fine. We are both working from the same database on a remote dev site.

    Still doesn’t work for me, and I am not sure we will ever know why.

  • There is something very strange going on between the first and second loop that should not be.

    
    // test
    echo '<b>values before first repeater</b><br />';
    echo 'POST: '; var_dump(acf_get_valid_post_id(false));
    echo '<br /><br />Active Loop: '; var_dump(acf_get_loop('active'));
    echo '<br /><br />Previous Loop: '; var_dump(acf_get_loop('previous'));
    acf_get_loop('active');
    if (have_rows('faq')) {
      while (have_rows('faq')) {
        the_row();
      }
    }
    echo '<b>values after first repeater</b><br />';
    echo 'POST: '; var_dump(acf_get_valid_post_id(false));
    echo '<br /><br />Active Loop: '; var_dump(acf_get_loop('active'));
    echo '<br /><br />Previous Loop: '; var_dump(acf_get_loop('previous'));
    acf_get_loop('active');
    if (have_rows('faq_column_2')) {
      while (have_rows('faq_column_2')) {
        the_row();
      }
    }
    
  • I tested your code, and this is what I get:

    values before first repeater
    POST: int(4)

    Active Loop: bool(false)

    Previous Loop: bool(false) values after first repeater
    POST: int(4)

    Active Loop: bool(false)

    Previous Loop: bool(false)

  • The last suggestion I have is to throw your content back into the mix and see what happens

    
    echo '<b>values before first repeater</b><br />';
    echo 'POST: '; var_dump(acf_get_valid_post_id(false));
    echo '<br /><br />Active Loop: '; var_dump(acf_get_loop('active'));
    echo '<br /><br />Previous Loop: '; var_dump(acf_get_loop('previous'));
    acf_get_loop('active');
    if (have_rows('faq')) {
      while (have_rows('faq')) {
        the_row();
        the_sub_field('question');
        the_sub_field('answer');
      }
    } else {
       echo 'No Rows<br />';
    }
    echo '<b>values after first repeater</b><br />';
    echo 'POST: '; var_dump(acf_get_valid_post_id(false));
    echo '<br /><br />Active Loop: '; var_dump(acf_get_loop('active'));
    echo '<br /><br />Previous Loop: '; var_dump(acf_get_loop('previous'));
    acf_get_loop('active');
    if (have_rows('faq_column_2')) {
      while (have_rows('faq_column_2')) {
        the_row();
        the_sub_field('question_col2'); 
        the_sub_field('answer_col2');
      }
    } else {
       echo 'No Rows<br />';
    }
    
  • Still no rows, but thanks for trying. I think I have some other issues going on.

  • It’s really strange, I really am stumped. If it were me I would start working in the ACF file, doing some debugging by outputting various values that ACF is using to determine the value returned by have_rows() and follow that until I could figure out where it’s going wrong. It really could be anything, but I would suspect a filter in some other part of the site, possibly some type of caching issue.

  • I posted this in a similar topic and I’ll post it here as well. This appears to be limited to specific installations. I would suggest to anyone that is having this issue to submit a support ticket and maybe the regular support team can work out what’s going on. https://support.advancedcustomfields.com/new-ticket/

  • I’m having the exact same issue. Wondering if anyone came up with a solution.

  • A little update on this.

    I’m writing a plugin that interfaces with WooCommerce. In the plugin I’m using ACF to attach custom repeater fields to a user which is then associated with a product. Anyhow, in the following code, get_students_1 returns the wrong list of students and get_students_2 returns the correct list. The two functions are identical.

    public function woocommerce_display_student_in_cart( $item_data, $cart_item ) 
    	{
    $this->get_students_1();
    $this->get_students_2();
    
    ...
    }
    	private function get_students_1()
    	{
    		print '<BR>---------STUDENTS 1--------<BR>';
    		
    		$user = 'user_'.$this->current_user->ID;
    		
    		
    		if( have_rows('student-list', $user) )
    		{
    			print "user has students<BR>";
    			
    			while( have_rows('student-list',$user ) ): the_row();
    
    				$currentName =  get_sub_field('student_name');
    		
    				print "** student $currentName <BR>";
    
    			endwhile;	
    		} 
    		else 
    		{
    			print "user has no students<BR>";
    		}
    	}
    	
    	private function get_students_2()
    	{
    		print '<BR>---------STUDENTS 2--------<BR>';
    		
    		$user = 'user_'.$this->current_user->ID;
    		
    		if( have_rows('student-list', $user) )
    		{
    			print "user has students<BR>";
    			
    			while( have_rows('student-list',$user ) ): the_row();
    	
    				$currentName =  get_sub_field('student_name');
    		
    				print "** student $currentName<BR>";
    	
    			endwhile;	
    			 
    		}
    		else 
    		{
    			print "user has no students<BR>";
    		}
    	}

    In fact, if I just call $this->get_students_1() twice, the first time the list is wrong and the second time it is correct.

    This is seriously confusing. Any ideas?

  • 6 month later and no one has fix for this.
    I have same problem, repeater returns only boolean value not an Array as it supposed to.
    One thing that I noticed if I don’t give a name to repeater field it DOES return an array, but I can’t select it because it’s identifier is [”] and php doesn’t want to read it.
    with name:

    ["address"]=>
      array(1) {
        ["list"]=>
        bool(false)
      }

    without name:

    ["address"]=>
      array(1) {
        [""]=>
        array(1) {
          [0]=>
          array(5) {
            ["type"]=>
            string(4) "Home"
            ["address"]=>
            string(23) "12324 SW MAIN ST"
            ["city"]=>
            string(10) "Beaverton "
            ["state"]=>
            string(2) "OR"
            ["zipcode"]=>
            string(5) "97007"
          }
        }
      }
  • UPDATE:
    So went with “no name” for repeater field (at this way I get something)
    I got this to work by removing the empty-name-array with foreach loop

    
    $address_list = Array();
    foreach ($app['address'] as $item) {
       $address_list = $item;
     }
     $app['address'] = $address_list;
    

    And now I have fully functioning associative Array

  • I have run across a similar issue, which was a repeater field returning a Boolean, and have found what was causing the problem for myself. I can’t say if its the same issue as the the original poster though.

    What was happening was I was calling the same problem field for a different reason before hand ( I was doing a check to see if the repeater fields rows existed), and then trying to call the objects later in my code from the same repeater field, which was returning a Boolean of false, instead of my objects i wanted.

    What seems to be happening, is that the repeater fields state, or function, or something, gets messed up when it is used before hand, and not returned to how it was before, or not being reset properly. I don’t know how this stuff is being handled exactly, but when i removed the first interaction with the field, it seems to be working fine.

    <?php if( have_rows('problem_field') ): ?>
      <?php $row_check = true; ?>
    <?php else: ?>
      <?php $row_check = false; ?>
    <?php endif; ?>
    
    <?php var_dump( get_sub_field('problem_field') ); ?>

    The var_dump will return a boolean of false

    Do the same thing, but essentially remove the checking of have rows.

    <?php if( true ): ?>
      <?php $row_check = true; ?>
    <?php else: ?>
      <?php $row_check = false; ?>
    <?php endif; ?>
    
    <?php var_dump( get_sub_field('problem_field') ); ?>

    var_dump now returns expected object values

    If i recall correctly, ive seen someone say that when they just try to call the same field twice, or cloned, or whatever, it also kinda breaks.

    this doesn’t solve the issue, but hopefully is helpful for someone.

Viewing 18 posts - 1 through 18 (of 18 total)

The topic ‘repeater field not returning data’ is closed to new replies.