Это код, который я пытаюсь использовать в function.php:
Код: Выделить всё
function test_get_acf() {
$field = get_field_object('credits');
$credits = array();
if( $field['choices'] ) {
foreach( $field['choices'] as $value => $label ) {
array_push($credits, $value);
}
}
$items = array(
'credits' => $credits
);
return $items;
}
Код: Выделить всё
function test_register_api_endpoints() {
register_rest_route( 'test/v2', '/acf', array(
'methods' => 'GET',
'callback' => 'test_get_acf',
) );
}
add_action( 'rest_api_init', 'test_register_api_endpoints' );
Код: Выделить всё
[
"credits": [ ]
]
Подробнее здесь: https://stackoverflow.com/questions/600 ... i-endpoint