[wp-hackers] Saving Posts Overwrites Post Meta Values Updated
Through AJAX
Doug Stewart
zamoose at gmail.com
Fri Dec 12 23:51:29 GMT 2008
On Fri, Dec 12, 2008 at 6:37 PM, Ronald Heft <ron at cavemonkey50.com> wrote:
> Hello everyone,
> 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
> through javascript, so when WordPress saves the post meta, it will replace
> 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
>
It does this updating from the posting screen...?
Why not use jQuery to alter/add to the contents of the form items?
--
-Doug
More information about the wp-hackers
mailing list