繁体   English   中英

如何在最新的Wordpress Rest API v2中获取原始值?

[英]How to get raw values in latest Wordpress Rest API v2?

当使用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 URL:

https://example.com/wp-json/wp/v2/media/32

编辑:我正在使用oAuth1进行身份验证( https://wordpress.org/plugins/rest-api-oauth1/ )。 鉴于未通过身份验证未返回原始值,我开始怀疑此插件在信息收集期间发送身份验证时遇到问题。

您必须通过'context'='edit'来获取原始内容。

或者您可以使用此插件: https : //github.com/w1z2g3/wordpress-plugins/blob/master/post-raw-content.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM