Вот код, который я использую:
Код: Выделить всё
function add_custom_fields_to_rest_api() {
register_rest_field(
'my_custom_post_type',
'my_custom_field',
array(
'get_callback' => 'get_custom_field_value',
'update_callback' => null,
'schema' => null,
)
);
}
function get_custom_field_value($object, $field_name, $request) {
return get_post_meta($object->ID, $field_name, true);
}
add_action('rest_api_init', 'add_custom_fields_to_rest_api');
Подробнее здесь: https://stackoverflow.com/questions/788 ... i-response