Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelschofield/7662001 to your computer and use it in GitHub Desktop.
Save michaelschofield/7662001 to your computer and use it in GitHub Desktop.
Extend the WP JSON API "Post" Controller to Modify Custom Field Values
// Add to the save() function in post.php
if ( !empty($values["custom"]) ) {
foreach ($values["custom"] as $metakey => $metavalue) {
update_post_meta($this->id,$metakey,$metavalue);
}
}
// create_post example
// http://localhost/site/?json=posts/create_post&dev=1&nonce=xxx&title=Post%20title&status=publish&custom[custom_field_1]=value1&custom[custom_field_2]=value2
// query for listing fields in response
http://localhost/site/?json=posts/create_post&dev=1&nonce=xxx&title=Post%20title&status=publish&custom[custom_field_1]=value1&custom[custom_field_2]=value2&custom_fields=custom_field_1,custom_field_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment