Expose Gutenberg blocks in Post Revisions API endpoint

I am working on a WordPress project with a headless front end, and am looking for a way to expose the individual post bl

I am working on a WordPress project with a headless front end, and am looking for a way to expose the individual post blocks when hitting the revisions endpoint. /

I used this code to expose each block as array item in my API request. /

Now I am trying to do the same thing with the revisions endpoint. It only returns the rendered content as one long string, instead of individual blocks. Does anyone now if this is possible?

thanks!

I am working on a WordPress project with a headless front end, and am looking for a way to expose the individual post blocks when hitting the revisions endpoint. https://developer.wordpress/rest-api/reference/post-revisions/

I used this code to expose each block as array item in my API request. https://wpscholar/blog/add-gutenberg-blocks-to-wp-rest-api/

Now I am trying to do the same thing with the revisions endpoint. It only returns the rendered content as one long string, instead of individual blocks. Does anyone now if this is possible?

thanks!

Share Improve this question asked Jun 17, 2019 at 15:46 Anton EmeryAnton Emery 431 silver badge4 bronze badges 2
  • I don't know, but it may be possible by looking at the endpoint for revision post type rather than the revisions API endpoint. – Nathan Powell Commented Jun 17, 2019 at 16:02
  • Good idea. It does give me the correct format, with the content split up by blocks. But the changes are not the latest, that is, everything prior to clicking the Preview button. I am querying wp-json/wp/v2/posts/219/?_embed&type=revision. Back to it... – Anton Emery Commented Jun 17, 2019 at 20:40
Add a comment  | 

1 Answer 1

Reset to default 0

Figured it out, after half a day of banging away and asking a team mate. In the wpscholar link above I changed this line of code.

// 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

This targets the post-revision type and returns its content in Gutenberg blocks.

Hopefully this is helpful to someone

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745392390a4625722.html

相关推荐

  • Expose Gutenberg blocks in Post Revisions API endpoint

    I am working on a WordPress project with a headless front end, and am looking for a way to expose the individual post bl

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信