[英]How to get raw values in latest Wordpress Rest API v2?
When requesting posts/pages/media with Wordpress Rest API v2 I used to receive a 'raw' and a 'rendered' value for fields like title, guid and content. 当使用Wordpress Rest API v2请求帖子/页面/媒体时,我曾经收到诸如标题,GUID和内容之类的字段的“原始”和“渲染”值。 With the latest Wordpress version the 'raw' fields seems to have vanished.
使用最新的Wordpress版本,“原始”字段似乎消失了。 I need the raw data as this is stable over time.
我需要原始数据,因为随着时间的推移这是稳定的。 Plugins can add (changing) data to the rendered data.
插件可以向渲染的数据添加(更改)数据。
Is there a (header) parameter I need to provide in the API call to get raw data? 我需要在API调用中提供一个(标头)参数以获取原始数据吗?
Original data returned (fragment): 返回的原始数据(片段):
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
)
Latest WP API data: 最新的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
)
The API URL: API URL:
https://example.com/wp-json/wp/v2/media/32 https://example.com/wp-json/wp/v2/media/32
Edit: I'm using oAuth1 for authentication ( https://wordpress.org/plugins/rest-api-oauth1/ ). 编辑:我正在使用oAuth1进行身份验证( https://wordpress.org/plugins/rest-api-oauth1/ )。 Given that raw values are not returned unauthenticated, I'm starting to suspect that this plugin has issues sending the authentication during the information gathering.
鉴于未通过身份验证未返回原始值,我开始怀疑此插件在信息收集期间发送身份验证时遇到问题。
You have to pass 'context' = 'edit' to get the raw content. 您必须通过'context'='edit'来获取原始内容。
Or you can use this plugin: https://github.com/w1z2g3/wordpress-plugins/blob/master/post-raw-content.php 或者您可以使用此插件: https : //github.com/w1z2g3/wordpress-plugins/blob/master/post-raw-content.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.