Support » Plugin: JSON API » [Plugin: JSON API] Creating post with a value for its custom_field

  • wprocks


    hi all,
    firstly great to be here and I love this JSON API plugin!

    I have a short question though, and hoping someone can help me out:

    In order to create a new post we do this:

    By setting custom_fields=1 , we can get the custom field object in the Post Response Object.

    I was wondering how can we create a post, with a specific value for its custom field?

    Take for instance, i have a custom_field and the key is competition.
    And I want to give it a value “summer”

    So perhaps i can do something like this:

    But the above request will not work, since this is not supported?

    I was wondering how can i creat a post with a specific value forits custom field ?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • in the post.php file there is the function save($values = null). simply add the following code to the end of this file

    foreach($values as $key => $value){
    if(strlen(strstr($key,’id’))==0 &&
    strlen(strstr($key,’type’))==0 &&
    strlen(strstr($key,’status’))==0 &&
    strlen(strstr($key,’title’))==0 &&
    strlen(strstr($key,’content’))==0 &&
    strlen(strstr($key,’author’))==0 &&
    strlen(strstr($key,’categories’))==0 &&
    strlen(strstr($key,’tags’))==0)//it must be a custom_field, so add it

    $wp_post = get_post($this->id);

    return $this->id;

    after that you should be able to create a post with custom values.
    According to your example simply call

    to add the value “summer” to your field competition

    Amazing! This is exactly what I needed thanks cohen!


    I solved this by adding the following in post.php in the save function:

    // add custom fields
      if ( !empty($values["custom"]) ) {
        	foreach ($values["custom"] as $metakey => $metavalue) {

    The query:


    Query for listing the fields in the response:


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: JSON API] Creating post with a value for its custom_field’ is closed to new replies.