In this case, I just wanted to make a custom field from ACF visible in the JSON returned for a custom post type which was named faculty.
add_action( 'rest_api_init', 'add_faculty_type_to_json' );
function add_faculty_type_to_json() {
register_rest_field(
'faculty', //the post type of your choice
'faculty_type', //the name for your json element
array(
'get_callback' => 'faculty_return_type', //the function that creates the content
)
);
}
// Return acf field staff_group
function faculty_return_type( $object, $field_name, $request ) {
global $post;
$faculty_type = get_field('staff_group', $post->ID);
return $faculty_type[0]; //multiple selections are possible here but in this use case I only want the first one
}
That’s all there is to it.