JavaScript - - By Michael Wanyoike

WordPress JSON Example

WordPress is an open-source Content Management System (CMS) that was launched in 2003. It’s actually a fork from another project known as b2/cafelog that began its roots way back in 2001. Today, WordPress is regarded as the most popular CMS platform and currently powers over 26% of the global web, according to WPManage. It also has about 60% market share, being the most used CMS.


July 27th, 2017: This article series was rewritten with up-to-date information and fresh examples.


In recent WordPress releases, the REST API was introduced as a built-in feature which opened the door for an endless list of new possibilities. Developers can now write new applications that interact with the site remotely by sending and receiving JSON data. You are no longer constrained to PHP – you are free to use whichever language you are most comfortable with provided it can interact with JSON.

In this example, I’ll show how to get a list of posts from a modern WordPress installation. For a better user experience, use Postman to interact with WordPress’ REST API.

You can launch Postman from this link:
Run in Postman

Once you have launched it, paste this link in the URL field:

http://www.sitepoint.com/wp-json/wp/v2/posts?per_page=3

Make sure GET command is selected. Hit the send button, after a few seconds, you will receive a JSON response. Below is a partial result of what it looks like:

[
  {
      "id": 157538,
      "date": "2017-07-21T10:30:34",
      "date_gmt": "2017-07-21T17:30:34",
      "guid": {
          "rendered": "https://www.sitepoint.com/?p=157538"
      },
      "modified": "2017-07-23T21:56:35",
      "modified_gmt": "2017-07-24T04:56:35",
      "slug": "why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it",
      "status": "publish",
      "type": "post",
      "link": "https://www.sitepoint.com/why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it/",
      "title": {
          "rendered": "Why the IoT Threatens Your WordPress Site (and How to Fix It)"
      },
      "content": {
         ...
      },
      "excerpt": {
          ...
      },
      "author": 72546,
      "featured_media": 157542,
      "comment_status": "open",
      "ping_status": "closed",
      "sticky": false,
      "template": "",
      "format": "standard",
      "meta": [],
      "categories": [
          6132
      ],
      "tags": [
          1798,
          6298
      ],

      }
  ]

I’ve truncated the content and the excerpt to show you a clear overview of the JSON response structure of a WordPress post. To learn more about the WordPress REST API, you should check out this tutorial and this one too.

Also: See more JSON examples.

Sponsors