Support

Account

Home Forums Bug Reports Programmatically inserting field with update_field() does not at _field_key meta Reply To: Programmatically inserting field with update_field() does not at _field_key meta

  • Hey!

    Typo, sorry. It’s update_field() of course and I’m setting basic text field value, so it’s a string.

    Really at a loss here after a few hours of digging around 🙂

    So, to write it down further (perhaps I find something odd now that I write it for someone else):

    $email = get_field($fields['org_email'], $ID); // $ID here is OK (printed in email that is sent)

    $fields is and array with field_id => field_key value pairs. This also seems to be working because a new post is added with the data via update_field() functions.

    And post is initially added like this:

    $post_id = wp_insert_post(
       array (
           'post_type' => 'my_post_type',
           'post_title' => 'Dynamic Name here',
           'post_status' => 'pending',
       )
    );
    
    // check if basic insertion was successful
    if( ! is_numeric($post_id)) {
        return false;
    } else { 
            
    $fields = lpml_get_acf_fields_key_name_map(); // this is field id => key value pair array
    
    update_field($fields['org_email'], $params_array['org_email'], $post_id); 

    This saves the data properly and all, except when I want to get the data via

    transition_post_status

    action it’s empty (empty string it seems). Is it to early to get this data here?

    When using ‘pending_to_publish’ hook for example, data is available …

    Is it possible, that values are not properly received because the post prior to this was still “pending” ? When I call update_field() the post was first inserted via wp_insert_post with the “status” => “pending”.