Home Forums Add-ons Repeater Field Create default rows for repeater Reply To: Create default rows for repeater

  • I found a way to do this.. I want to know if this is the ideal way of achieving this?
    Is there another way to add the update code instead of else:

    $rowvalue = get_field('quick_links', 'user_' . $user_id);
    // check if the repeater field has rows of data
    if( have_rows('quick_links', 'user_' . $user_id) ):
        // loop through the rows of data
        while ( have_rows('quick_links', 'user_' . $user_id) ) : the_row();
            // Testing field output
            the_sub_field('icon', 'user_' . $user_id);
            echo "<br />";
            the_sub_field('title', 'user_' . $user_id);
            echo "<br />";
            the_sub_field('link', 'user_' . $user_id);
            echo "<br />";
            echo "<br />";
    else :
    $updated_value = array
      array("icon"=>"fa-align-justify","title"=>"Link 1","link"=>""),
     array("icon"=>"fa-align-justify","title"=>"Link 2","link"=>""),
      array("icon"=>"fa-align-justify","title"=>"Link 3","link"=>""),
    update_field('quick_links', $updated_value , 'user_' . $user_id);