Support

Account

Home Forums Add-ons Flexible Content Field Infinite loop using user_id

Solved

Infinite loop using user_id

  • I have created a field in the backend that applies to each user. When I add values to a user and log in as that user it displays the value set in the back end but then infinitely loops the while loop. The result is a infinite string of End of if after the values set in the user account.

    $user_id = get_current_user_id();
    $values = have_rows('user_notification', 'user_'.$user_id);
    
    if ($values){
    	echo 'Is set <br><br>';
    
    	while ($values) { the_row();
    		if (get_row_layout() == 'notification') {
    			the_sub_field('notification_title');
    		}
            echo 'End of if <br>';
        }
    }
  • This returns true or false

    
    $values = have_rows('user_notification', 'user_'.$user_id);
    

    Which means that

    
    while ($values)
    

    is always true

    The correct way to do this loop is

    
    if (have_rows('user_notification', 'user_'.$user_id)) {
      while (have_rows('user_notification', 'user_'.$user_id)) {
        the_row();
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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.