After much scrutiny and a much needed lunch break, I found that the reason it returned false was $thing
needed to be the following:
$thing = $object['taxonomy'] . "_" . $object['id'];
My mistake! I was returning the slug of a specific ‘region’ instead of literally the taxonomy/term slug.
I accepted your answer, although there is a typo with a missing ‘}’
Unfortunately, that’s not my result. I’m getting false
. Here’s my code that isn’t working. I’m trying to use the WP REST API to return custom fields on a custom Taxonomy called ‘region’ on a custom Post Type.
function regions_get_custom_fields_cb($object, $field_name, $request){
$thing = $object['slug'] . "_" . $object['id'];
return get_fields($thing);
}
add_action('rest_api_init', function(){
register_rest_field('region', 'custom_data',
array(
'get_callback' => 'regions_get_custom_fields_cb',
'update_callback' => null,
'schema' => null
)
);
});