I’ve added a single Advanced Custom Field to the categories taxonomy (that appears to work as expected) and am trying to retrieve it along with the categories using the REST API, via /wp-json/wp/v2/categories.

I’ve managed to customise the posts JSON returned, using the rest_prepare_post filter…

function prepare_restful_posts($data, $post, $request) {
    // Do stuff to $data
}
add_filter('rest_prepare_post', 'prepare_restful_posts', 10, 3);

…but I can’t seem to find any helpful information about how to customise the categories JSON.

Can someone possibly shed some light on this?

1 Answer
1

Turns out it’s the helpfully titled rest_prepare_categoryfilter

function prepare_restful_categories($response, $item, $request) {
    // Do stuff to categories
}
add_filter('rest_prepare_category', 'prepare_restful_categories', 10, 3);

Leave a Reply

Your email address will not be published. Required fields are marked *