WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Update Custom Fields of Post (3 posts)

  1. regularsteven
    Member
    Posted 8 months ago #

    Is there a method that supports updating (or creation) of custom fields?

    Updating the title seems simple (eg): /api/posts/update_post/?post_type=myob_product&id=8&title=New%20Product%20Title&nonce=48c6acc362

    It seems that appending custom_tags only filters out what is returned, but ideally, I could append:
    &custom_fields[tagLine]=Sweet%20Product%20Tag%20Line and the update_post would act accordingly.

    Thanks very much, loving this plugin

    http://wordpress.org/plugins/json-api/

  2. monkeypunch3
    Member
    Posted 8 months ago #

  3. monkeypunch3
    Member
    Posted 8 months ago #

    It matters where you add the code so I'm updating this reply.

    In the models/post.php in the save() method after this code:

    if (isset($wp_values['ID'])) {
        $this->id = wp_update_post($wp_values);
    } else {
        $this->id = wp_insert_post($wp_values);
    }

    add this code:

    // support for custom fields
    if ( !empty($values["custom"]) ) {
        foreach ($values["custom"] as $metakey => $metavalue) {
           update_post_meta($this->id,$metakey, $metavalue);
        }
    }

    Then instead of "&name=value" submit the form , "custom[name]=value".

Reply

You must log in to post.

About this Plugin

About this Topic