0

After couple of nights of searching and trying various approaches, I haven't found any solution.

Issue

Cache not clearing after saving manually 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. The changes can be seen when 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. So the values are not fetched from the database, but from cache. 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 is the right way to flush Wordpress's cache?

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.

Edit:

Forgot to mention earlier, that no Cache plugins is being used.

7
  • So where's the cache then? WordPress doesn't cache things between requests AFAIK, unless you set up a cache plugin or an object cache. Are you sure it's not just your browser cache?
    – Rup
    Oct 14 '21 at 19:58
  • @Rup Wordpress seems to have it's own Object cache. This is something new for me too. More info: developer.wordpress.org/reference/classes/wp_object_cache Oct 14 '21 at 20:05
  • True but it won't cache across requests unless you add use a plugin to e.g. move the cache into memcached: "By default, the object cache is non-persistent. This means that data stored in the cache resides in memory only and only for the duration of the request."
    – Rup
    Oct 14 '21 at 20:07
  • Well, if that's the case, then I'm really confused with this issue. I can see in my database, that meta data X has a value A, but frontend displays value B. If this is not caused by cache, then what could it be? Oct 14 '21 at 20:14
  • 1
    @tiagocalado I doubt it's something to do with variables. Any of used variable doesn't apply both in this tool and on frontend. Ie. tool uses diffrent variables (in different class) than frontend. I have narrowed down the reason of this issue and it's related to Advanced Custom Fields. When I pull the metadata out with get_post_meta(), I get the correct data while ACF get_field() function is showing the wrong data. I have posted this same question to ACF support forum, but I'll leave this question here, if someone with same issue has an answer. Oct 15 '21 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.