Search code examples
wordpressmeta

Wordpress update_post_meta not saving


Is there any funky caching/versioning going on with Wordpress that I should know in regards to meta data against a post?

I am building a plugin and when I update a meta value, I can see that it updates it (by adding a die() statement after my call to update_post_meta and looking in mysql), but when I let the page load continue, the value hasn't changed (and it has reverted back in mysql).

Any ideas? If I delete the value from the post and then try update, it creates it correctly. It's just updates that don't stick!


Solution

  • So the problem was that my code was updating the value, but then Woocommerce was then saving the values it received from the form POST over my values. The solution was to hook into an action that is called after the form is saved, so that my data is saved after Woocommerce has done it's save.