When using the WordPress REST API, by default, HTML formatted content in rendered
format is returned. However, there are times when you need content in raw
format, that is, original data before formatting. Such cases can be handled by adding specific parameters to the API request.
Methods for retrieving raw content
To retrieve raw
content with the REST API, add the context=edit
parameter to the request URL. This will allow you to retrieve the raw content before the content
property is formatted. However, this parameter is usually only applicable to authenticated users, so authentication is required.
Example request
GET https://yourwebsite.com/wp-json/wp/v2/posts/{post_id}?context=edit
This request will return the post with the specified post_id
in raw
format, allowing you to retrieve content that contains HTML tags and unencoded data.
Cautions and Importance of Authentication
The context=edit
parameter is generally only applicable to administrators or users with editing privileges. Therefore, authentication using OAuth, application password, or API key is required at the time of request.
Uses and Applications
Content in raw
format, including custom field data, can be useful when working with plugins, theme development, and custom applications. It can also be used to retrieve raw data from posts and process it in your own style.