Support

Account

Home Forums Add-ons Repeater Field get_field() for repeater returning string instead of array Reply To: get_field() for repeater returning string instead of array

  • 
    // get repeater using get_post_meta()
    $repeater = 'repeater'; // name of repeater field
    $sub_fields = array(
      // holds names of all sub fields
      'sub_field_1',
      'sub_field_2',
      'sub_field_3'
    );
    // init rows
    $rows = array();
    // repeater meta holds number of rows
    $count = intval(get_post_meta($post_id, $repeater, true);
    for ($i=0; $i<$count; $i++) {
      // build row
      $row = array();
      foreach ($sub_fields as $sub_field) {
        $row[$sub_field] = get_post_meta($post_id, $repeater.'_'.$i.'_'.$sub_field, true);
      }
      $rows[] = $row;
    }