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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.