簡體   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