Home › Forums › Add-ons › Repeater Field › repeater field not returning data › Reply To: repeater field not returning data
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?
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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.