WordPress返回所有_link的rest_api值

时间:2019-09-02 13:51:30

标签: wordpress wordpress-rest-api wordpress-gutenberg

我有一个wordpress网站,我在其中依赖大量帖子中的嵌入式数据,例如作者,类别,特色媒体和标签。最近,REST api开始为所有rest_url值返回相同的_links值,随后为所有_embedded数据返回相同的根站点数据。所以打电话给:

[GET] /wp-json/wp/v2/posts/123?_embed

返回如下结构:

{
  "id": 123,
  ...,
  "_links": {
    "self":       [{ href: "<rest_url>" }],
    "collection": [{ href: "<rest_url>" }],
    "about":      [{ href: "<rest_url>" }],
    "author":     [{ href: "<rest_url>", embeddable: true }],
    "replies":    [{ href: "<rest_url>", embeddable: true }],
    ...,
  ]
}

<rest_url>rest_url过滤器函数返回的值:

add_filter('rest_url', function() {
  return `<rest_url>`;
});

我能够通过更新rest_url过滤器功能来恢复功能,但是我不确定根本原因是什么,因为此代码片段在本地或其他实例上不会引起相同的问题。临时解决方案如下:

add_filter('rest_url', function( $path = ''){
  $url = str_replace("https://example.com//", '', $path);
  return "https://api.example.com/wp-json/{$url}";
});

是什么会导致wordpress api仅返回所有rest_url值的_links

0 个答案:

没有答案