将字段添加到wp api类别请求

时间:2017-01-09 12:44:59

标签: wp-api wordpress-rest-api

我可以在wp api post请求中添加字段,即

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

并使用哪个过滤器?

0 个答案:

没有答案