0

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
  • Did you figure this out? I think rest_prepare_{$this->taxonomy} might be the filter you are looking for. Commented Apr 23, 2017 at 18:22

1 Answer 1

1
function slug_add_data_c($response, $post) {

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

    return $response;
}

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.