[wp-hackers] Saving Posts Overwrites Post Meta Values Updated
ron at cavemonkey50.com
Fri Dec 12 23:37:42 GMT 2008
I'm writing a plugin that uses ajax to update a custom set post meta value.
My ajax works correctly, and I am able to update the post meta value (using
the standard update_post_meta function). However, I'm finding that when
saving the post, any updates I have made to that post meta field are lost.
WordPress on a save goes through each of the meta values on a post, and
overwrites the database value with the one returned through $_POST. By doing
this, anything updated in the database since the user last refreshed the
page is lost.
I have through of a couple of different ideas to solve the issue, but
neither are ideal.
My first idea is through an action grab the database value and replace it
with the $_POST value before a save. Unfortunately, there doesn't appear to
be any hooks that run before the post meta values are updated.
The other idea I thought of was to update the post's meta value field
it with the correctly updated values. While this will work, I find the
method to be extremely hacky, and I'm thinking there has to be a better way
to do it through PHP.
Surely there has to be some developer out there who is using post meta
values with AJAX and have run into this issue. Does anyone have any better
ideas to deal with this issue?
Ronald Heft, Jr.
Information Sciences and Technology
Pennsylvania State University
More information about the wp-hackers