Support

Account

Home Forums Add-ons Repeater Field Update field in Repeater field

Solving

Update field in Repeater field

    • alam7o

    • July 23, 2020 at 10:44 pm

    I tried to update field with form in Repeater field
    This is my code for update field in single.php

    if(isset($_POST['submit'])){
      if( have_rows('custom_req') ){
        while( have_rows('custom_req') ){ the_row(); 
          $r_req = get_sub_field('req_fie');
          if ($_POST['radio-b'] == $r_req ) { 
            update_sub_field('rq_answer', 'new_value');
          }
        }
      }
    }
    if( have_rows('custom_req') ){
      while( have_rows('custom_req') ){ the_row(); 
        the_sub_field('rq_answer'); // This line shows the previous value
      }
    }

    the sub field after click updated but,
    the problem is shows the previous value, and the page must be reloaded to show the new value
    Why is that? How do I solve this problem?
    Thanks for any help

  • Are you actually trying to get the values immediately after updating?

    Is this in your template file? If it is your first if

    
    if(isset($_POST['submit'])){
    

    should never run since this value should not be set when the template file is loading.

    • alam7o

    • July 27, 2020 at 8:01 am

    Thanks for answer,
    in fact i solved this problem
    now my question is , Is this method safe?
    i want user can update field when click submit

Viewing 3 posts - 1 through 3 (of 3 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.