admin管理员组

文章数量:1426198

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

本文标签: Expose Gutenberg blocks in Post Revisions API endpoint