Support

Account

Home Forums Bug Reports update_field function with post object is adding single value wrong

Unread

update_field function with post object is adding single value wrong

  • I’m trying to add data via the function update_field.
    The field type is “Post Object” and “Select multiple values?” is set to no. When I update the field the normal way via the interface (selecting a value, and then updating), the single value is saved correctly.
    But, if I try to do it like this: update_field('destination', 749, $id);, it save the value as as array.
    So when I try to get the data with get_field('destination', $id);, I get an array with the single Post Object, rather than just the Post Object. Am I doing something wrong, or is it a bug?

    I know I can check if it’s an array or Object, and then just take the first item in the array if so, but it’s rather annoying to have to do that, when it’s not what you expect.

Viewing 1 post (of 1 total)

The topic ‘update_field function with post object is adding single value wrong’ is closed to new replies.