[wp-hackers] Saving Posts Overwrites Post Meta Values Updated
Through AJAX
Ronald Heft
ron at cavemonkey50.com
Sat Dec 13 00:06:31 GMT 2008
Correct, this occurs from the edit post screen when saving posts.
That is the solution I came up with (solution #2), but there are
some drawbacks to this that make it seem more like a hack.
First off, the data I'm storing in a post meta is serialized, as most of the
data stored is created through PHP. To update the form field, the data would
have to be submitted through AJAX, processed through PHP, returned in
javascript, and updated in the field.
Second, I'm already returning data on my AJAX query, and that data is used
for displaying information to the user. To return the serialized array, I
would have to create a second AJAX query to update the form field.
Again, this idea will work, but it seems way too hacky and not
an elegant solution. I would think there should be to specify in WordPress
that this field may change through AJAX or other means before a post save.
I'm already using an underscore to hide the field from the user, the user
should not have any access to that field, and therefore there should be no
reason for WordPress to assume that is the most current version of the post
meta.
--
Ronald Heft, Jr.
Information Sciences and Technology
Pennsylvania State University
ronaldheft.com
cavemonkey50.com
On Fri, Dec 12, 2008 at 6:51 PM, Doug Stewart <zamoose at gmail.com> wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list