In version two of the WordPress REST API, several improvements have been made regarding how custom fields are handled in WordPress. If you haven’t downloaded version two yet, you can do so via WordPress.org or by cloning the “develop” branch of the official GitHub repo for the project. In this article, you’ll learn how to edit and create post meta fields using the WordPress REST API and how to retrieve or update metadata for a post. You’ll also learn how to customize the default endpoints for a post to expose post meta or other data related to a post. While this article mainly discusses post meta, it can be largely applied to user meta as well. Getting Meta Fields With The REST API Assuming you have the REST API installed and that you’re familiar with getting and updating posts via the REST API, you probably know how to work with the main post data. You most like know that if you query for a post, your meta fields for the posts are not included. There is an endpoint for post meta, but it requires authentication. Before we get into this, you need to learn how to expose meta fields in the main post route. This will allow a meta field to show up in a request for a post or a group of posts
Share This