有人知道如何让自定义post类型的摘录出现在WordPress REST API中吗?
发布于 2018-06-22 16:40:42
我想你现在已经成功地解决了这个问题,但对于那些偶然发现这篇文章寻求帮助的人(就像我一样),下面的方法对我很有效:
add_filter("rest_prepare_{$post_type}", function ($response) {
$response->data['excerpt'] = get_the_excerpt();
return $response;
});
链接:
https://developer.wordpress.org/reference/hooks/rest_prepare_this-post_type/ https://codex.wordpress.org/Function_Reference/get_the_excerpt
发布于 2017-07-04 18:31:01
你可以在REST API响应中获取摘录,如下所示,这是post的默认摘录,
示例响应JSON数据,
"excerpt":{
"rendered":"<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!<\/p>\n",
"protected":false
},
https://stackoverflow.com/questions/44895011
复制相似问题