Support

Account

Home Forums Add-ons Repeater Field Repeater Code Pulls Inconsistent Results

Unread

Repeater Code Pulls Inconsistent Results

  • 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?

Viewing 1 post (of 1 total)

The topic ‘Repeater Code Pulls Inconsistent Results’ is closed to new replies.