These are chat archives for WP-API/node-wpapi

14th
Aug 2017
sunpietro
@sunpietro
Aug 14 2017 07:11

@dumbledork yes, there is a way to update post meta. It's not that obvious, but you have to do something similar to this:

<?php

function rest_api_player_meta() {
    register_rest_field('sp_player', 'player_meta', array(
           'update_callback' => 'update_player_meta',
           'schema' => null,
        )
    );
}

function update_player_meta($meta, $post) {
    $postId = $post->ID;

    foreach ($meta as $data) {
        update_post_meta($postId, $data['key'], $data['value']);
    }
}

add_action('rest_api_init', 'rest_api_player_meta');

you have to update post endpoint to use a specific callback: update_callback

there you'll be able to update post meta with update_post_meta function
yuanweiqi
@yuanweiqi
Aug 14 2017 08:18
test