Wordpress REST API module for nodejs


Layer to get resources from WordPress using the [developer.wordpress.com/docs/api/](REST API).

Create a new instance of WPCONN. If you wanna a way to get the access token then can use WPOAuth npm module.

var WPCONN = require('wp-connect');
var wpconn = WPCONN();
var WPCONN = require('wp-connect');
var wpconn = new WPCONN('<your token>');
// get the user info 
  // user info related with the given access token 

Set site identifier

Get the site information

var WPCONN = require('wp-connect');
var wpconn = new WPCONN('<your token here>');
// get site info 
  // site data object 

Get the site posts

wpconn.site.posts({ number: 10 }, function(errposts){
  // posts array 

WPCONN.site.post.get(id, fn);

Get post site data

// get post data 
wpconn.site.post.get(435, params, function(errpost){
  // post data object 

WPCONN.site.post.getBySlug(slug, params, fn);

Get post site data by the given slug

// get post data 
wpconn.site.post.getBySlug('we-are-the-loosers', function(errpost){
  // post data object 

WPCONN.site.post.add(data, fn);

Add a new post

// post data 
var data = {
  "title": "A new post",
  "slug": "a-new-post",
  "content": "<div>The content of the new post</div>"
wpconn.site.post.add(data, function(errnew_post){
  // object data of the new post already added 

WPCONN.site.post.edit(id, data, fn);

Edit a post

wpconn.site.post.edit(321, { title: "new Title !!!" }, function(erredit_post){
  // the title in edit_post has changed 

Into example/ folder download the npm dependencies:

$ npm install

... and then run the application

$ node index.js

Create data.json file into test/ folder to can run the tests. You can copy or rename the test/data_example.json file.

  "client_id": "<your client_id here>",
  "client_secret": "<your client_secret here>",
  "token": "<your token app here>",
  "public_site": "<a public blog here>",
  "private_site": "<a private blog here>",
  "private_site_id": "<the ID of the private blog>",
  "new_post_data": {
    "title": "New testing post",
    "content": "<div style=\"color: red;\">The content of the new testing post</div>"

... and then

$ make

MIT – Copyright 2014 Automattic