Support

Account

Home Forums Add-ons Repeater Field get_post_meta for a repeater field Reply To: get_post_meta for a repeater field

  • when using get_post_meta()

    The field that is your repeater field will return the # of rows in the repeater field.
    What you need to get is the meta value of the sub field meta key and the actual key will look something like
    {repeater-field-name}_{#}_{sub-field} where {#} is the index of the of the row, starting at 0.

    So you need to first get the value from the repeater field, then do a for loop and build the meta_key values and then get each sub field value.

    
    $repeater_value = get_post_meta($post_id, 'repeater_field_name', true);
    if ($repeater_value) {
      for ($i=0; $i<$repeater_value, $i++) {
        $meta_key = 'repeater_field_name_'.$i.'_sub_field_name';
        $sub_field_value = get_post_meta($post_id, $meta_key, true);
      }
    }
    

    what you do from there will depend on what is stored in the sub field.