Support

Account

Home Forums General Issues Using update field for a post object field inside a flexible content field

Helping

Using update field for a post object field inside a flexible content field

  • Hi!

    I am trying to use update_field to update a flexible content field. It works ok and creates a new flexible content entry with the right layout as expected.

    One of the fields in the flexible content entry I create is a post object field. The field is set to only allow a single post, not multiple. The field name is ‘measure’ and I am passing it a value of 65 (which is a valid post ID) but the field is not saved within the flexible content entry.

    My code is this:

    $new_meta = get_field('related_measures', $new_id);
    if(!$new_meta){
     $new_meta = array();
    }
    $update = array( 'measure' => 65, "acf_fc_layout" => 'existing_measures' );
    array_push($new_meta, $update);
    update_field( 'field_57b5c93eded8f', $new_meta, 66 );
    

    Any ideas why this won’t work?

    Thank you

    James

    ______________________________________

    EDIT:

    I have since discovered it is saving the post id ok, but it is not showing the post in the dropdown in the field in the post editor.

    It does appear as a value in an invisible input field as part of the select2 stuff, but isn’t in the select values or shown as a selected option.

    So it seems like maybe this is a field display in the editor issue maybe?

  • Try using the field key instead of the field name

    
    $update = array( 'field_9876543212' => 65, "acf_fc_layout" => 'existing_measures' );
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using update field for a post object field inside a flexible content field’ is closed to new replies.