Home › Forums › Backend Issues (wp-admin) › update_field is not working in action hook › Reply To: update_field is not working in action hook
It can be confusing, but just because you see the field in the database does not mean the field is registered when you are trying to update it. I don’t know the entire sequence of events that are fired when you use the draft_to_publish hook or what files may or may not be loaded at the time.
But that really did not answer my question. Are the fields registered in a function? Is this function run on a hook? Are are the calls to the ACF function just at the top level of the file outside of any functions?
As a test to see if the field is registered, if you want to do some debugging, just before you try to call update_field() for this update you can try getting the field object.
$field = get_field_object('field_YOUR-FIELD-KEY');
var_dump($field);
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.