Fixing the WP REST API content_raw Problem [...]

I think I figured out how to fix the problem where the REST API in WordPress is applying filters to my content.

It seems to be on line 1089 of class-wp-rest-posts-controller in plugins/rest-api/lib/endpoints. The apply_filters line there executes it.

class-wp-rest-post-controllers (in endpoints)

I can’t change the authentication without making a whole big mess, but I think if I just set this from the apply_filters version to

‘raw’ => $post->post_content,
/** This filter is documented in wp-includes/post-template.php */
‘rendered’ => $post->post_content,

This will work. I don’t need any server rendering, so for my purposes this is fine.

It does make it hard to distribute this though — every update potentially overwrites this change. Plus asking people to change a line in the core distribution just seems wrong.

But maybe this is a workaround until WordPress makes aversion of content_raw available to unauthenticated users.

Wikity users can copy this article to their own site for editing, annotation, or safekeeping. If you like this article, please help us out by copying and hosting it.

Destination site (your site)
Posted on