Support

Account

Home Forums General Issues Update sub field, then get value Reply To: Update sub field, then get value

  • Hi al, Thanks for your reply, I managed to find a trick to solve this problem by using the native WordPress get_post_meta function, the idea is as follow:

    
    $lists = get_field('lists', $post->ID);
    
    $len= 0; // To get the number of rows
    foreach ($lists as $key => $list) {
      update_sub_field(array('lists', $key, 'field'), 0, $post->ID);
      $len++;  
    }
    
    $result = array();
    
    for($i= 0; $i < $len; $i++) {
      $result[$i]= array(
        "field" => get_post_meta($post->ID, "lists_".$i."_field", true),
      );
    }
    
    var_dump($result);
    

    You have just to take a look about how ACF name the post meta fields here: http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/

    Regards