Home › Forums › Backend Issues (wp-admin) › WP Admin updates differently in DB than update_field() ?
I’m building a front end form that creates a new post with wp_insert_post() via an AJAX handler. Once I’ve created the post ID, I then use a foreach loop to update_field().
issue: get_field_object() doesn’t work on the fields I created with update_field(). However, when I update in WP Admin, it works.
This is my AJAX handler: https://bitbucket.org/snippets/ChristopherArter/n4RRy and I’ve verified in the browser console that the javascript object is correct and that everything on that end is good.
I’ve got a posts management table that on the front end to display the posts created and it works great.. as long as the post was created or updated from the WP Admin. If not, the get_field_object() doesn’t work, and it’s a mess.
I took a look in the database, and you’ll see for post 949, the top image is what was saved to the database when I use the update_field() function and the AJAX handler above. The image below is what happens when I go into the WP Admin and hit “Update” on the very same post, which in turn, the get_field_object() works great and everything is good.
See the database here: http://imgur.com/a/y3moJ
I’m not really familiar with ACF, so I don’t know what that serialization on the end of the ‘field_’ identifier is..
Any suggestions on how to get this working as it does when I update from Admin?
Hi @chrisarter
There’s no info on how your $cleanData
looks like in your snippet but my guess is that you’re using the field names as key?
Thing is that if you’re doing update_field
for not previously existing values you have to use the field key rather than the field name. Otherwise the matching table value _fieldname
with the field key as value aren’t created and because of that you’re going to have trouble using functions like get_field_object()
.
The reason it’ll work after you manually hit update is because then ACF itself saves the values for the post with the field key present (so now you’ll have both values in your database).
Just use the field keys instead and you’ll be good to go! These are hidden by default but can be turned on from the screen options in the top right corner.
The topic ‘WP Admin updates differently in DB than update_field() ?’ is closed to new replies.
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.