Deleting A WordPress Blog Post Using The WordPress REST API
The NextJs application allows users to delete blog posts using the WordPress REST API by sending HTTP DELETE requests to the endpoint specified by the WordPress Developers website.
Users are required to login before the delete button appears for a blog post. Upon clicking the delete button the user is provided visual feedback that the post has been deleted in the form of a red background for the post listing.
The following code extract provides detail on how the request is sent, using the fetchJSON function. Much of the contents of this functional component have been omitted due to its length, with the most important part of the mechanism being shown below.
Deleting posts using WordPress can be achieved by sending an HTTP DELETE request to the https://example.com/wp-json/wp/v2/posts/<id> route where the <id> slug is equal to the ID of the post to be deleted.
References
WordPress (n.d.). Posts | REST API Handbook. [online] WordPress Developer Resources. Available at: https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post [Accessed 1 May 2021].




Comments
Post a Comment