我能够向 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
并使用哪个过滤器?