I am trying to update my acf with update-post-meta:

update_post_meta($my_post, 'ganalytics_settings', serialize($ganalytics_settings));

$ganalytics_settings is an array, which I would like to store serialized within the field.

enter image description here

However, I get the following condition is not met(taken from meta.php):

function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') {
    global $wpdb;

    if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {
        return false; //I am getting here in, but I do not know why.

Any suggestions what I might do wrong?

I appreciate your reply!

1 Answer 1


Arrays are serialized by default, so just do

update_post_meta($my_post, 'ganalytics_settings', $ganalytics_settings);


$meta_value (mixed) (required) The new value of the custom field. A passed array will be serialized into a string.(this should be raw as opposed to sanitized for database queries) Default: None

Also, make sure that $my_post is post ID, not the post object.

And, if you want to update ACF field, you should use it's update_field function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.