I am working on a project that involves using wpapi for nodejs to interact with WordPress posts. I want to update an existing post by adding some new content to its original content. However, I am facing a problem with the content field of the wpapi response. When I use wp.posts() to get the content of a post, I only see the rendered result, which does not include any shortcodes that are present in the WordPress editor. If I simply append some data to this content and use PUT to update the post, I will lose the shortcodes and mess up the formatting of the post. How can I solve this problem? Is there a way to get the raw content of a post as it is in WordPress, or to append content without affecting the shortcodes? I appreciate any help or guidance on this issue. Thank you.
One possible solution to your problem is to use the `content.rendered` and `content.raw` fields of the wpapi response. The `content.rendered` field contains the HTML output of the post content, which includes the shortcodes. The `content.raw` field contains the raw text of the post content, which does not include the shortcodes. You can use these fields to manipulate the content of a post without losing the shortcodes.
For example, suppose you want to add some new content to the end of an existing post. You can use the following steps:
1. Use `wp.posts().id(postId).get()` to get the post object with the `content.rendered` and `content.raw` fields.
2. Use a regular expression or a HTML parser to extract the shortcodes from the `content.rendered` field and store them in an array.
3. Use a string concatenation or a template literal to append your new content to the `content.raw` field.
4. Use a loop or a map function to insert the shortcodes back into the `content.raw` field at their original positions.
5. Use `wp.posts().id(postId).update({content: content.raw})` to update the post with the modified content.
This way, you can update an existing post by adding some new content to its original content without affecting the shortcodes or the formatting of the post. I hope this helps you with your project.