如何指定Wordpress API v2的字段

问题描述 投票:3回答:3

我在项目中使用WordPress REST API并将GET请求发送至:

http://myblog/wp-json/wp/v2/posts  

并且它的工作正常,但是我不知道如何指定字段。我看过文档,但仍然不知道如何去做。例如,使用公共API:

https://public-api.wordpress.com/rest/v1.1/sites/www.mysite.com/posts?number=100&fields=title,excerpt,featured_image 

仅返回指定的字段。如何使用v2 API?

wordpress wordpress-rest-api
3个回答
2
投票

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/

如此处所述,REST API v2返回一组特定的默认字段,如果您需要不同的默认字段,则必须按照该文档中的说明implement


1
投票

此问题的简单解决方案是使用ACF to REST API或等效的插件,可以为您扩展REST API。我已经在许多网站上成功使用了此插件。

如果这不可能,那么您将需要修改答案,如其他答案所述。您可以阅读有关here的更多信息。


0
投票

我知道这很旧,但对于仍在寻找的人-使用_ fields查询参数

https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields

© www.soinside.com 2019 - 2024. All rights reserved.