有谁知道如何将自定义帖子类型的摘录显示在WordPress REST API中?
您可以在下面的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 },
我想你现在已经成功地解决了这个问题,但对于那些偶然发现这篇文章寻求帮助的人(正如我所做的那样),以下内容对我有用:
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
2 回答
您可以在下面的REST API响应中摘录,这是post的默认摘录,
示例响应JSON数据,
我想你现在已经成功地解决了这个问题,但对于那些偶然发现这篇文章寻求帮助的人(正如我所做的那样),以下内容对我有用:
链接:
https://developer.wordpress.org/reference/hooks/rest_prepare_this-post_type/ https://codex.wordpress.org/Function_Reference/get_the_excerpt