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!
❓Ever wondered when and why ACF uses JSON instead of the database? Check out our summary of the most recent session of ACF Chat Friday for the answer, and make sure to register for the next session.
— Advanced Custom Fields (@wp_acf) February 23, 2023
👉 https://t.co/3UtvQbDwNmhttps://t.co/wfFEVcXVKc
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.