使用Wordpress Rest API v2请求帖子/页面/媒体时,我曾经收到过标题,guid和内容等字段的“原始”和“呈现”值。使用最新的Wordpress版本,“原始”字段似乎已经消失。我需要原始数据,因为这是稳定的。插件可以向渲染数据添加(更改)数据。
我需要在API调用中提供一个(头)参数来获取原始数据吗?
返回原始数据(片段):
Array
(
[id] => 1016
[date] => 2017-11-08T16:18:29
[date_gmt] => 2017-11-08T15:18:29
[guid] => Array
(
[rendered] => https://example.com/wp-content/uploads/2017/03/image.jpg
[raw] => https://example.com/wp-content/uploads/2017/03/image.jpg
)
[modified] => 2017-11-08T16:18:39
[modified_gmt] => 2017-11-08T15:18:39
[slug] => 888
[status] => inherit
[type] => attachment
[link] => https://example.com/review/shopper/attachment/test/
[title] => Array
(
[raw] => shopper image
[rendered] => shopper image
)
最新的WP API数据:
Array
(
[id] => 1016
[date] => 2017-11-08T16:18:29
[date_gmt] => 2017-11-08T15:18:29
[guid] => Array
(
[rendered] => https://example.com/wp-content/uploads/2017/03/image.jpg
)
[modified] => 2017-11-08T16:18:39
[modified_gmt] => 2017-11-08T15:18:39
[slug] => 888
[status] => inherit
[type] => attachment
[link] => https://example.com/review/shopper/attachment/test/
[title] => Array
(
[rendered] => shopper image
)
API网址:
https://example.com/wp-json/wp/v2/media/32
编辑: 我正在使用oAuth1进行身份验证(https://wordpress.org/plugins/rest-api-oauth1/)。鉴于原始值未经过未经验证的返回,我开始怀疑此插件在信息收集过程中发送身份验证时出现问题。
答案 0 :(得分:1)
您必须传递'context'='edit'以获得原始内容。
或者您可以使用以下插件:https://github.com/w1z2g3/wordpress-plugins/blob/master/post-raw-content.php