Home Forums General Issues Matching $_POST key and ACF field name Reply To: Matching $_POST key and ACF field name

  • You have the field names and are looking for the field keys. It would be possible to do this if those fields already exist in the database for the post using get_field_object($field_name, $post_id) However, since you are creating post then these fields do not exist and there isn’t any way to match them up.

    You have to know the field keys.

    You could build an array of field name => field key pairs

    $fields = array(
      'field_name_1' => 'field_key_1',
      'field_name_2' => 'field_key_2',
      // etc...
    foreach ($_POST as $field_name => $value) {
      update_field($fields[$field_name], $value, $post_id);