WordPress at Your Fingertips

How to delete Post-meta-fields using WordPress REST API

Let's say we've registered the meta-field some_metakey to work with it in the REST API. We can update its value using a POST request. But how do we delete this meta-field?

DELETE requests by default only work for the REST resource (post object), and there is no meta-field resource in the WP REST API. Therefore, at the moment, it is not possible to delete the value of a meta-field using the DELETE method in the WordPress REST API.

So what to do?

Updating/adding meta-fields is done when inserting and updating post objects, so to "delete" the meta-field, you need to provide an empty value when updating the current value. In this case, the WP REST API will delete the meta-field.

Plugin

I found a small plugin on GitHub that extends the capabilities of the REST API and allows working with post metadata, taxonomies.

https://github.com/csalzano/wp-api-manipulate-meta

The plugin adds new routes:

  • /wp-json/wp/v2/{post_type}/{post_id}/meta/{meta_key}
  • /wp-json/wp/v2/{taxonomy}/{term_id}/meta/{meta_key}
1 comment
    Log In