title: How do you add custom fields defined in posts to the rest API responses in wordpress
body: <p>I want to do this without using any sort of plugin since these are both core wordpress features (custom fields and the REST API). Here is the documentation for custom fields for reference:</p>
  
  <p><a href="https://codex.wordpress.org/Using_Custom_Fields" rel="nofollow noreferrer">https://codex.wordpress.org/Using_Custom_Fields</a></p>
  
  <p>Here is a screenshot from my wordpress installation:</p>
  
  <p><a href="https://i.stack.imgur.com/E4Zkz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4Zkz.png" alt="wordpress custom fields"></a></p>
  
  <p>Here is what the API response for a post looks like currently:</p>
  
  <pre><code>{
      "_links": {
          "about": [
              {
                  "href": "http://example.com/wp-json/wp/v2/types/post"
              }
          ],
          "author": [
              {
                  "embeddable": true,
                  "href": "http://example.com/wp-json/wp/v2/users/1"
              }
          ],
          "collection": [
              {
                  "href": "http://example.com/wp-json/wp/v2/posts"
              }
          ],
          "curies": [
              {
                  "href": "https://api.w.org/{rel}",
                  "name": "wp",
                  "templated": true
              }
          ],
          "replies": [
              {
                  "embeddable": true,
                  "href": "http://example.com/wp-json/wp/v2/comments?post=21"
              }
          ],
          "self": [
              {
                  "href": "http://example.com/wp-json/wp/v2/posts/21"
              }
          ],
          "version-history": [
              {
                  "href": "http://example.com/wp-json/wp/v2/posts/21/revisions"
              }
          ],
          "wp:attachment": [
              {
                  "href": "http://example.com/wp-json/wp/v2/media?parent=21"
              }
          ],
          "wp:featuredmedia": [
              {
                  "embeddable": true,
                  "href": "http://example.com/wp-json/wp/v2/media/23"
              }
          ],
          "wp:term": [
              {
                  "embeddable": true,
                  "href": "http://example.com/wp-json/wp/v2/categories?post=21",
                  "taxonomy": "category"
              },
              {
                  "embeddable": true,
                  "href": "http://example.com/wp-json/wp/v2/tags?post=21",
                  "taxonomy": "post_tag"
              }
          ]
      },
      "author": 1,
      "categories": [
          5,
          4
      ],
      "comment_status": "open",
      "content": {
          "protected": false,
          "rendered": ""
      },
      "date": "2017-05-14T15:25:33",
      "date_gmt": "2017-05-14T15:25:33",
      "excerpt": {
          "protected": false,
          "rendered": ""
      },
      "featured_media": 23,
      "format": "standard",
      "guid": {
          "rendered": "http://example.com/?p=21"
      },
      "id": 21,
      "link": "http://example.com/2017/05/14/post/",
      "meta": [],
      "modified": "2017-05-15T18:17:34",
      "modified_gmt": "2017-05-15T18:17:34",
      "ping_status": "open",
      "slug": "",
      "sticky": false,
      "tags": [],
      "template": "",
      "title": {
          "rendered": ""
      },
      "type": "post"
  }
  </code></pre>
  
  <p>In case it could be relevant, here are my active plugins:</p>
  
  <p><a href="https://i.stack.imgur.com/GrFyS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GrFyS.png" alt="list of active wordpress plugins: Enable Media Replace, S3 Uploads"></a></p>