Home › Forums › Front-end Issues › update_field values not showing on frontend
After couple of nights of searching and trying various approaches, I haven’t found any solution.
Issue
I suspect that ACF’s cache is not clearing after saving programmatically post meta.
I’m creating a tool for admins, which will update custom post type’s meta data (ACF-fields) with command update_field()
Changes are being saved to the database and changes can be seen when editing the post. And actually the new values can be seen anywhere in backend.
On the frontend new saved meta data can’t be seen, but there’s old values that doesn’t exist in the database anymore. In other words: on frontend meta data is showing value A, and in database is stored value B.
So the values are not fetched from the database, but from cache, I think. If I update the post in the edit post view, then the new values will show on frontend. But instructing users to go editing post and save it after using this mentioned tool, is not good practice.
So what am I not noticing?
What have been tried
This is what I have already tried: After update_field()
I’ve run:
wp_cache_delete()
clean_post_cache()
update_post_caches()
wp_cache_flush()
$wpdb->flush()
These functions didn’t empty the cache. Am I perhaps using them wrong?
I’m doing the developing in Local by Flywheel, which is using Nginx. I suspected about Nginx and switched to Apache, but that didn’t help. So Nginx isn’t causing the issue. And now as I’m developing the site, there is no cache plugins being used.
When you use update_field()
on a field that has not data it is not updated correctly if you use the field name. When calling update_field()
for fields that were not previously set you must use the field key. update_field($field_key, $vale, $post_id)
This is explained in the documentation https://www.advancedcustomfields.com/resources/update_field/
You must be logged in to reply to this topic.
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.