Last active
December 29, 2015 11:09
-
-
Save michaelschofield/7662001 to your computer and use it in GitHub Desktop.
Extend the WP JSON API "Post" Controller to Modify Custom Field Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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