[wp-hackers] Write a custom field to a new post via JS??

Matthew Gerring mgerring at emrl.com
Fri Jan 8 19:59:11 UTC 2010


I got it figured out- I'm just hooking into existing actions in admin-ajax.php.

There's already an add-meta action, and the only reason I couldn't get it to work was my lack of understanding of how nonces work. Once I generated the nonce using wp_create_nonce('add-meta'), everything worked perfectly.

The only problem I have now is constructing the request properly for updating the meta as opposed to adding a new meta item, but it's getting there.

The code is here: http://wordpress.pastebin.com/m38869391

The error handling is messed up, since there are 3 or 4 different error codes returned by add-meta, but for the most part it works.

Also, it looks like WordPress re-loads the media buttons on autosave. You can tell media buttons to look for a positive ID before displaying, and they become visible once there's an available ID.

On Jan 7, 2010, at 7:21 AM, Dylan Kuhn wrote:

>> One of the problems is that the wp_postmeta table can't store negative ids.
> 
> I also ran into this and would be interested to know what you end up
> doing. For now I hide my ajax buttons on new posts, and just process
> posted data on the save_post action instead, when the real ID is
> available.
> 
> -dylan-
> _______________________________________________
> 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