Home Forums Feedback update_field() clarification Reply To: update_field() clarification

  • This all depends on where this is happening.

    For example, if you can see the ACF field on the page that you’re submitting, then the field and key reference are being created when you click on the update button. You are in fact updating a field that already exists in the database.

    Before updating the value you can probably see this with something like

    echo 'is it set?<br />';
    echo 'last_viewed = ',get_post_meta($this->_wp_id, 'last_viewed', true),'<br />';
    echo '_last_viewed = ',get_post_meta($this->_wp_id, '_last_viewed', true),'<br />';
    $now_value = current_time("Y-m-d H:i:s");
    update_field("last_viewed", $now_value, $this->_wp_id);

    You need to use the key only under conditions where the field is guaranteed to not exist. This can happen when you are creating posts in code.