0

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.org/rest-api/reference/post-revisions/

I used this code to expose each block as array item in my API request. https://wpscholar.com/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!

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. 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... Jun 17, 2019 at 20:40

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.