我正在开发一个具有无头前端的WordPress项目,并且正在寻找一种方法,在触及修订端点时公开各个post块。https://developer.wordpress.org/rest-api/reference/post-revisions/
我使用这段代码将每个块公开为API请求中的数组项。https://wpscholar.com/blog/add-gutenberg-blocks-to-wp-rest-api/
现在,我试图对修订端点做同样的事情。它只将呈现的内容作为一个长字符串返回,而不是单个块。如果有可能的话,现在还有人吗?
谢谢!
发布于 2019-06-17 21:57:53
在花了半天时间去找个队友之后,我想出了个办法。在上面的wp学者链接中,我更改了这一行代码。
// Surface all Gutenberg blocks in the WordPress REST API
$post_types = get_post_types_by_support( [ 'editor' ] ); // change this line
$post_types = ['post', 'page', 'post-revision']; // to this
它以修改后的类型为目标,并在Gutenberg块中返回其内容。
希望这对某人有帮助
https://wordpress.stackexchange.com/questions/340723
复制相似问题