0

我能够向 wp api 发布请求添加字段,即

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

像这样使用 rest_prepare_post 过滤器:

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 );

如何向 wp api 类别请求添加字段,即

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

并使用哪个过滤器?

4

1 回答 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);

于 2017-08-11T14:10:24.117 回答