add fields to wp api categories request

725 views Asked by At

I am able to add fields to wp api post request i.e.

http://demo.wp-api.org/wp-json/wp/v2/posts

using rest_prepare_post filter like this :

function my_rest_prepare_post( $data, $post, $request ) {
    $_data = $data->data;
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $thumbnail = wp_get_attachment_image_src( $thumbnail_id );
    $_data['featured_image_thumbnail_url'] = $thumbnail[0];
    $data->data = $_data;
    return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );

How can I add fields to wp api categories request i.e.

http://demo.wp-api.org/wp-json/wp/v2/categories

and using which filter?

1

There are 1 answers

0
Simon Berton On
function slug_add_data_c($response, $post) {

    $response->data['latitud'] = 'Hello';

    return $response;
}

add_filter('rest_prepare_category', 'slug_add_data_c', 10, 3);