为了满足我的需要,我定制了wp rest posts回调:
function get_all_posts( $data, $post, $context ) {
return [
\'id\' => $data->data[\'id\'],
\'date\' => $data->data[\'date\'],
\'date_gmt\' => $data->data[\'date_gmt\'],
\'modified\' => $data->data[\'modified\'],
\'title\' => $data->data[\'title\'][\'rendered\'],
\'content\' => $data->data[\'content\'][\'rendered\'],
\'excerpt\' => $data->data[\'excerpt\'][\'rendered\'],
\'category\' => get_the_category_by_ID( $data->data[\'categories\'][0] ),
\'link\' => $data->data[\'link\'],
];
}
add_filter( \'rest_prepare_post\', \'get_all_posts\', 10, 3 );
类别端点直接返回帖子类别的名称。