curl POST work with user meta but not the custom user meta

arguments get_callback and update_callback receive different arguments.

try this exemple which works for a field user_continent

add_action("rest_api_init", function () {


    register_rest_field(
          "user"
        , "user_continent"
        ,
        [
            "get_callback" => function ($user, $field_name, $request, $object_type) {

                return get_user_meta($user["id"], $field_name, TRUE);

            },
            "update_callback" => function ($value, $user, $field_name, $request, $object_type) {

                update_user_meta($user->ID, $field_name, $value);

            },
        ]
    );


});

Leave a Comment